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

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

Issue 2399373002: Only advance |first_seq_num_| if packets are explicitly cleared from the PacketBuffer. (Closed)
Patch Set: Compile fix 2 Created 4 years, 2 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
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 return; 42 return;
43 } 43 }
44 frames_from_callback_.insert( 44 frames_from_callback_.insert(
45 std::make_pair(frame->first_seq_num(), std::move(frame))); 45 std::make_pair(frame->first_seq_num(), std::move(frame)));
46 } 46 }
47 47
48 enum IsKeyFrame { kKeyFrame, kDeltaFrame }; 48 enum IsKeyFrame { kKeyFrame, kDeltaFrame };
49 enum IsFirst { kFirst, kNotFirst }; 49 enum IsFirst { kFirst, kNotFirst };
50 enum IsLast { kLast, kNotLast }; 50 enum IsLast { kLast, kNotLast };
51 51
52 void InsertPacket(uint16_t seq_num, // packet sequence number 52 bool Insert(uint16_t seq_num, // packet sequence number
53 IsKeyFrame keyframe, // is keyframe 53 IsKeyFrame keyframe, // is keyframe
54 IsFirst first, // is first packet of frame 54 IsFirst first, // is first packet of frame
55 IsLast last, // is last packet of frame 55 IsLast last, // is last packet of frame
56 int data_size = 0, // size of data 56 int data_size = 0, // size of data
57 uint8_t* data = nullptr) { // data pointer 57 uint8_t* data = nullptr) { // data pointer
58 VCMPacket packet; 58 VCMPacket packet;
59 packet.codec = kVideoCodecGeneric; 59 packet.codec = kVideoCodecGeneric;
60 packet.seqNum = seq_num; 60 packet.seqNum = seq_num;
61 packet.frameType = keyframe ? kVideoFrameKey : kVideoFrameDelta; 61 packet.frameType = keyframe ? kVideoFrameKey : kVideoFrameDelta;
62 packet.isFirstPacket = first == kFirst; 62 packet.isFirstPacket = first == kFirst;
63 packet.markerBit = last == kLast; 63 packet.markerBit = last == kLast;
64 packet.sizeBytes = data_size; 64 packet.sizeBytes = data_size;
65 packet.dataPtr = data; 65 packet.dataPtr = data;
66 66
67 EXPECT_TRUE(packet_buffer_->InsertPacket(packet)); 67 return packet_buffer_->InsertPacket(packet);
68 } 68 }
69 69
70 void CheckFrame(uint16_t first_seq_num) { 70 void CheckFrame(uint16_t first_seq_num) {
71 auto frame_it = frames_from_callback_.find(first_seq_num); 71 auto frame_it = frames_from_callback_.find(first_seq_num);
72 ASSERT_FALSE(frame_it == frames_from_callback_.end()) 72 ASSERT_FALSE(frame_it == frames_from_callback_.end())
73 << "Could not find frame with first sequence number " << first_seq_num 73 << "Could not find frame with first sequence number " << first_seq_num
74 << "."; 74 << ".";
75 } 75 }
76 76
77 const int kStartSize = 16; 77 const int kStartSize = 16;
78 const int kMaxSize = 64; 78 const int kMaxSize = 64;
79 79
80 Random rand_; 80 Random rand_;
81 std::unique_ptr<Clock> clock_; 81 std::unique_ptr<Clock> clock_;
82 rtc::scoped_refptr<PacketBuffer> packet_buffer_; 82 rtc::scoped_refptr<PacketBuffer> packet_buffer_;
83 std::map<uint16_t, std::unique_ptr<RtpFrameObject>> frames_from_callback_; 83 std::map<uint16_t, std::unique_ptr<RtpFrameObject>> frames_from_callback_;
84 }; 84 };
85 85
86 TEST_F(TestPacketBuffer, InsertOnePacket) { 86 TEST_F(TestPacketBuffer, InsertOnePacket) {
87 uint16_t seq_num = Rand(); 87 const uint16_t seq_num = Rand();
88 InsertPacket(seq_num, kKeyFrame, kFirst, kLast); 88 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kLast));
89 } 89 }
90 90
91 TEST_F(TestPacketBuffer, InsertMultiplePackets) { 91 TEST_F(TestPacketBuffer, InsertMultiplePackets) {
92 uint16_t seq_num = Rand(); 92 const uint16_t seq_num = Rand();
93 InsertPacket(seq_num, kKeyFrame, kFirst, kLast); 93 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kLast));
94 InsertPacket(seq_num + 1, kKeyFrame, kFirst, kLast); 94 EXPECT_TRUE(Insert(seq_num + 1, kKeyFrame, kFirst, kLast));
95 InsertPacket(seq_num + 2, kKeyFrame, kFirst, kLast); 95 EXPECT_TRUE(Insert(seq_num + 2, kKeyFrame, kFirst, kLast));
96 InsertPacket(seq_num + 3, kKeyFrame, kFirst, kLast); 96 EXPECT_TRUE(Insert(seq_num + 3, kKeyFrame, kFirst, kLast));
97 } 97 }
98 98
99 TEST_F(TestPacketBuffer, InsertDuplicatePacket) { 99 TEST_F(TestPacketBuffer, InsertDuplicatePacket) {
100 uint16_t seq_num = Rand(); 100 const uint16_t seq_num = Rand();
101 InsertPacket(seq_num, kKeyFrame, kFirst, kLast); 101 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kLast));
102 InsertPacket(seq_num, kKeyFrame, kFirst, kLast); 102 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kLast));
103 }
104
105 TEST_F(TestPacketBuffer, SeqNumWrap) {
106 EXPECT_TRUE(Insert(0xFFFF, kKeyFrame, kFirst, kLast));
107 EXPECT_TRUE(Insert(0x0, kKeyFrame, kFirst, kLast));
108
109 CheckFrame(0xFFFF);
110 }
111
112 TEST_F(TestPacketBuffer, InsertOldPackets) {
113 const uint16_t seq_num = Rand();
114
115 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast));
116 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kFirst, kLast));
117 EXPECT_TRUE(Insert(seq_num + 1, kKeyFrame, kNotFirst, kLast));
118 ASSERT_EQ(2UL, frames_from_callback_.size());
119
120 frames_from_callback_.erase(seq_num + 2);
121 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast));
122 ASSERT_EQ(1UL, frames_from_callback_.size());
123
124 frames_from_callback_.erase(frames_from_callback_.find(seq_num));
125 ASSERT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast));
126 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kFirst, kLast));
127
128 packet_buffer_->ClearTo(seq_num + 2);
129 EXPECT_FALSE(Insert(seq_num + 2, kDeltaFrame, kFirst, kLast));
130 EXPECT_TRUE(Insert(seq_num + 3, kDeltaFrame, kFirst, kLast));
131 ASSERT_EQ(2UL, frames_from_callback_.size());
103 } 132 }
104 133
105 TEST_F(TestPacketBuffer, NackCount) { 134 TEST_F(TestPacketBuffer, NackCount) {
106 uint16_t seq_num = Rand(); 135 const uint16_t seq_num = Rand();
107 136
108 VCMPacket packet; 137 VCMPacket packet;
109 packet.codec = kVideoCodecGeneric; 138 packet.codec = kVideoCodecGeneric;
110 packet.seqNum = seq_num; 139 packet.seqNum = seq_num;
111 packet.frameType = kVideoFrameKey; 140 packet.frameType = kVideoFrameKey;
112 packet.isFirstPacket = true; 141 packet.isFirstPacket = true;
113 packet.markerBit = false; 142 packet.markerBit = false;
114 packet.timesNacked = 0; 143 packet.timesNacked = 0;
115 144
116 packet_buffer_->InsertPacket(packet); 145 packet_buffer_->InsertPacket(packet);
117 146
118 packet.seqNum++; 147 packet.seqNum++;
119 packet.isFirstPacket = false; 148 packet.isFirstPacket = false;
120 packet.timesNacked = 1; 149 packet.timesNacked = 1;
121 packet_buffer_->InsertPacket(packet); 150 packet_buffer_->InsertPacket(packet);
122 151
123 packet.seqNum++; 152 packet.seqNum++;
124 packet.timesNacked = 3; 153 packet.timesNacked = 3;
125 packet_buffer_->InsertPacket(packet); 154 packet_buffer_->InsertPacket(packet);
126 155
127 packet.seqNum++; 156 packet.seqNum++;
128 packet.markerBit = true; 157 packet.markerBit = true;
129 packet.timesNacked = 1; 158 packet.timesNacked = 1;
130 packet_buffer_->InsertPacket(packet); 159 packet_buffer_->InsertPacket(packet);
131 160
132
133 ASSERT_EQ(1UL, frames_from_callback_.size()); 161 ASSERT_EQ(1UL, frames_from_callback_.size());
134 RtpFrameObject* frame = frames_from_callback_.begin()->second.get(); 162 RtpFrameObject* frame = frames_from_callback_.begin()->second.get();
135 EXPECT_EQ(3, frame->times_nacked()); 163 EXPECT_EQ(3, frame->times_nacked());
136 } 164 }
137 165
138 TEST_F(TestPacketBuffer, FrameSize) { 166 TEST_F(TestPacketBuffer, FrameSize) {
139 uint16_t seq_num = Rand(); 167 const uint16_t seq_num = Rand();
140 uint8_t data[] = {1, 2, 3, 4, 5}; 168 uint8_t data[] = {1, 2, 3, 4, 5};
141 169
142 InsertPacket(seq_num, kKeyFrame, kFirst, kNotLast, 5, data); 170 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast, 5, data));
143 InsertPacket(seq_num + 1, kKeyFrame, kNotFirst, kNotLast, 5, data); 171 EXPECT_TRUE(Insert(seq_num + 1, kKeyFrame, kNotFirst, kNotLast, 5, data));
144 InsertPacket(seq_num + 2, kKeyFrame, kNotFirst, kNotLast, 5, data); 172 EXPECT_TRUE(Insert(seq_num + 2, kKeyFrame, kNotFirst, kNotLast, 5, data));
145 InsertPacket(seq_num + 3, kKeyFrame, kNotFirst, kLast, 5, data); 173 EXPECT_TRUE(Insert(seq_num + 3, kKeyFrame, kNotFirst, kLast, 5, data));
146 174
147 ASSERT_EQ(1UL, frames_from_callback_.size()); 175 ASSERT_EQ(1UL, frames_from_callback_.size());
148 EXPECT_EQ(20UL, frames_from_callback_.begin()->second->size); 176 EXPECT_EQ(20UL, frames_from_callback_.begin()->second->size);
149 } 177 }
150 178
151 TEST_F(TestPacketBuffer, ExpandBuffer) { 179 TEST_F(TestPacketBuffer, ExpandBuffer) {
152 uint16_t seq_num = Rand(); 180 const uint16_t seq_num = Rand();
153 181
154 for (int i = 0; i < kStartSize + 1; ++i) { 182 for (int i = 0; i < kStartSize + 1; ++i) {
155 InsertPacket(seq_num + i, kKeyFrame, kFirst, kLast); 183 EXPECT_TRUE(Insert(seq_num + i, kKeyFrame, kFirst, kLast));
156 } 184 }
157 } 185 }
158 186
187 TEST_F(TestPacketBuffer, SingleFrameExpandsBuffer) {
188 const uint16_t seq_num = Rand();
189
190 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast));
191 for (int i = 1; i < kStartSize; ++i)
192 EXPECT_TRUE(Insert(seq_num + i, kKeyFrame, kNotFirst, kNotLast));
193 EXPECT_TRUE(Insert(seq_num + kStartSize, kKeyFrame, kNotFirst, kLast));
194
195 ASSERT_EQ(1UL, frames_from_callback_.size());
196 CheckFrame(seq_num);
197 }
198
159 TEST_F(TestPacketBuffer, ExpandBufferOverflow) { 199 TEST_F(TestPacketBuffer, ExpandBufferOverflow) {
160 uint16_t seq_num = Rand(); 200 const uint16_t seq_num = Rand();
161 201
162 for (int i = 0; i < kMaxSize; ++i) { 202 for (int i = 0; i < kMaxSize; ++i)
163 InsertPacket(seq_num + i, kKeyFrame, kFirst, kLast); 203 EXPECT_TRUE(Insert(seq_num + i, kKeyFrame, kFirst, kLast));
164 } 204 EXPECT_FALSE(Insert(seq_num + kMaxSize + 1, kKeyFrame, kFirst, kLast));
165
166 VCMPacket packet;
167 packet.seqNum = seq_num + kMaxSize + 1;
168 EXPECT_FALSE(packet_buffer_->InsertPacket(packet));
169 } 205 }
170 206
171 TEST_F(TestPacketBuffer, OnePacketOneFrame) { 207 TEST_F(TestPacketBuffer, OnePacketOneFrame) {
172 uint16_t seq_num = Rand(); 208 const uint16_t seq_num = Rand();
173 InsertPacket(seq_num, kKeyFrame, kFirst, kLast); 209 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kLast));
174 ASSERT_EQ(1UL, frames_from_callback_.size()); 210 ASSERT_EQ(1UL, frames_from_callback_.size());
175 CheckFrame(seq_num); 211 CheckFrame(seq_num);
176 } 212 }
177 213
178 TEST_F(TestPacketBuffer, TwoPacketsTwoFrames) { 214 TEST_F(TestPacketBuffer, TwoPacketsTwoFrames) {
179 uint16_t seq_num = Rand(); 215 const uint16_t seq_num = Rand();
180 216
181 InsertPacket(seq_num, kKeyFrame, kFirst, kLast); 217 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kLast));
182 InsertPacket(seq_num + 1, kKeyFrame, kFirst, kLast); 218 EXPECT_TRUE(Insert(seq_num + 1, kKeyFrame, kFirst, kLast));
183 219
184 EXPECT_EQ(2UL, frames_from_callback_.size()); 220 EXPECT_EQ(2UL, frames_from_callback_.size());
185 CheckFrame(seq_num); 221 CheckFrame(seq_num);
186 CheckFrame(seq_num + 1); 222 CheckFrame(seq_num + 1);
187 } 223 }
188 224
189 TEST_F(TestPacketBuffer, TwoPacketsOneFrames) { 225 TEST_F(TestPacketBuffer, TwoPacketsOneFrames) {
190 uint16_t seq_num = Rand(); 226 const uint16_t seq_num = Rand();
191 227
192 InsertPacket(seq_num, kKeyFrame, kFirst, kNotLast); 228 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast));
193 InsertPacket(seq_num + 1, kKeyFrame, kNotFirst, kLast); 229 EXPECT_TRUE(Insert(seq_num + 1, kKeyFrame, kNotFirst, kLast));
194 230
195 EXPECT_EQ(1UL, frames_from_callback_.size()); 231 EXPECT_EQ(1UL, frames_from_callback_.size());
196 CheckFrame(seq_num); 232 CheckFrame(seq_num);
197 } 233 }
198 234
199 TEST_F(TestPacketBuffer, ThreePacketReorderingOneFrame) { 235 TEST_F(TestPacketBuffer, ThreePacketReorderingOneFrame) {
200 uint16_t seq_num = Rand(); 236 const uint16_t seq_num = Rand();
201 237
202 InsertPacket(seq_num, kKeyFrame, kFirst, kNotLast); 238 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast));
203 InsertPacket(seq_num + 2, kKeyFrame, kNotFirst, kLast); 239 EXPECT_TRUE(Insert(seq_num + 2, kKeyFrame, kNotFirst, kLast));
204 InsertPacket(seq_num + 1, kKeyFrame, kNotFirst, kNotLast); 240 EXPECT_TRUE(Insert(seq_num + 1, kKeyFrame, kNotFirst, kNotLast));
205 241
206 EXPECT_EQ(1UL, frames_from_callback_.size()); 242 EXPECT_EQ(1UL, frames_from_callback_.size());
207 CheckFrame(seq_num); 243 CheckFrame(seq_num);
208 } 244 }
209 245
210 TEST_F(TestPacketBuffer, DiscardOldPacket) { 246 TEST_F(TestPacketBuffer, Frames) {
211 VCMPacket packet; 247 const uint16_t seq_num = Rand();
212 packet.seqNum = Rand();
213 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
214 packet.seqNum += 2;
215 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
216 248
217 for (int i = 3; i < kMaxSize; ++i) { 249 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kLast));
218 ++packet.seqNum; 250 EXPECT_TRUE(Insert(seq_num + 1, kDeltaFrame, kFirst, kLast));
219 EXPECT_TRUE(packet_buffer_->InsertPacket(packet)); 251 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kFirst, kLast));
220 } 252 EXPECT_TRUE(Insert(seq_num + 3, kDeltaFrame, kFirst, kLast));
221
222 ++packet.seqNum;
223 EXPECT_FALSE(packet_buffer_->InsertPacket(packet));
224 packet_buffer_->ClearTo(packet.seqNum + 1);
225 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
226 }
227
228 TEST_F(TestPacketBuffer, DiscardMultipleOldPackets) {
229 uint16_t seq_num = Rand();
230 VCMPacket packet;
231 packet.seqNum = seq_num;
232 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
233 packet.seqNum += 2;
234 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
235
236 for (int i = 3; i < kMaxSize; ++i) {
237 ++packet.seqNum;
238 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
239 }
240
241 packet_buffer_->ClearTo(seq_num + 15);
242 for (int i = 0; i < 15; ++i) {
243 ++packet.seqNum;
244 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
245 }
246 for (int i = 15; i < kMaxSize; ++i) {
247 ++packet.seqNum;
248 EXPECT_FALSE(packet_buffer_->InsertPacket(packet));
249 }
250 }
251
252 TEST_F(TestPacketBuffer, Frames) {
253 uint16_t seq_num = Rand();
254
255 InsertPacket(seq_num, kKeyFrame, kFirst, kLast);
256 InsertPacket(seq_num + 1, kDeltaFrame, kFirst, kLast);
257 InsertPacket(seq_num + 2, kDeltaFrame, kFirst, kLast);
258 InsertPacket(seq_num + 3, kDeltaFrame, kFirst, kLast);
259 253
260 ASSERT_EQ(4UL, frames_from_callback_.size()); 254 ASSERT_EQ(4UL, frames_from_callback_.size());
261 CheckFrame(seq_num); 255 CheckFrame(seq_num);
262 CheckFrame(seq_num + 1); 256 CheckFrame(seq_num + 1);
263 CheckFrame(seq_num + 2); 257 CheckFrame(seq_num + 2);
264 CheckFrame(seq_num + 3); 258 CheckFrame(seq_num + 3);
265 } 259 }
266 260
261 TEST_F(TestPacketBuffer, ClearSinglePacket) {
262 const uint16_t seq_num = Rand();
263
264 for (int i = 0; i < kMaxSize; ++i)
265 EXPECT_TRUE(Insert(seq_num + i, kDeltaFrame, kFirst, kLast));
266
267 packet_buffer_->ClearTo(seq_num);
268 EXPECT_TRUE(Insert(seq_num + kMaxSize, kDeltaFrame, kFirst, kLast));
269 }
270
271 TEST_F(TestPacketBuffer, OneIncompleteFrame) {
272 const uint16_t seq_num = Rand();
273
274 EXPECT_TRUE(Insert(seq_num, kDeltaFrame, kFirst, kNotLast));
275 EXPECT_TRUE(Insert(seq_num + 1, kDeltaFrame, kNotFirst, kLast));
276 EXPECT_TRUE(Insert(seq_num - 1, kDeltaFrame, kNotFirst, kLast));
277
278 ASSERT_EQ(1UL, frames_from_callback_.size());
279 CheckFrame(seq_num);
280 }
281
282 TEST_F(TestPacketBuffer, TwoIncompleteFramesFullBuffer) {
283 const uint16_t seq_num = Rand();
284
285 for (int i = 1; i < kMaxSize - 1; ++i)
286 EXPECT_TRUE(Insert(seq_num + i, kDeltaFrame, kNotFirst, kNotLast));
287 EXPECT_TRUE(Insert(seq_num, kDeltaFrame, kFirst, kNotLast));
288 EXPECT_TRUE(Insert(seq_num - 1, kDeltaFrame, kNotFirst, kLast));
289
290 ASSERT_EQ(0UL, frames_from_callback_.size());
291 }
292
267 TEST_F(TestPacketBuffer, FramesReordered) { 293 TEST_F(TestPacketBuffer, FramesReordered) {
268 uint16_t seq_num = Rand(); 294 const uint16_t seq_num = Rand();
269 295
270 InsertPacket(seq_num + 1, kDeltaFrame, kFirst, kLast); 296 EXPECT_TRUE(Insert(seq_num + 1, kDeltaFrame, kFirst, kLast));
271 InsertPacket(seq_num, kKeyFrame, kFirst, kLast); 297 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kLast));
272 InsertPacket(seq_num + 3, kDeltaFrame, kFirst, kLast); 298 EXPECT_TRUE(Insert(seq_num + 3, kDeltaFrame, kFirst, kLast));
273 InsertPacket(seq_num + 2, kDeltaFrame, kFirst, kLast); 299 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kFirst, kLast));
274 300
275 ASSERT_EQ(4UL, frames_from_callback_.size()); 301 ASSERT_EQ(4UL, frames_from_callback_.size());
276 CheckFrame(seq_num); 302 CheckFrame(seq_num);
277 CheckFrame(seq_num + 1); 303 CheckFrame(seq_num + 1);
278 CheckFrame(seq_num + 2); 304 CheckFrame(seq_num + 2);
279 CheckFrame(seq_num + 3); 305 CheckFrame(seq_num + 3);
280 } 306 }
281 307
282 TEST_F(TestPacketBuffer, GetBitstreamFromFrame) { 308 TEST_F(TestPacketBuffer, GetBitstreamFromFrame) {
283 // "many bitstream, such data" with null termination. 309 // "many bitstream, such data" with null termination.
284 uint8_t many[] = {0x6d, 0x61, 0x6e, 0x79, 0x20}; 310 uint8_t many[] = {0x6d, 0x61, 0x6e, 0x79, 0x20};
285 uint8_t bitstream[] = {0x62, 0x69, 0x74, 0x73, 0x74, 0x72, 311 uint8_t bitstream[] = {0x62, 0x69, 0x74, 0x73, 0x74, 0x72,
286 0x65, 0x61, 0x6d, 0x2c, 0x20}; 312 0x65, 0x61, 0x6d, 0x2c, 0x20};
287 uint8_t such[] = {0x73, 0x75, 0x63, 0x68, 0x20}; 313 uint8_t such[] = {0x73, 0x75, 0x63, 0x68, 0x20};
288 uint8_t data[] = {0x64, 0x61, 0x74, 0x61, 0x0}; 314 uint8_t data[] = {0x64, 0x61, 0x74, 0x61, 0x0};
289 uint8_t 315 uint8_t
290 result[sizeof(many) + sizeof(bitstream) + sizeof(such) + sizeof(data)]; 316 result[sizeof(many) + sizeof(bitstream) + sizeof(such) + sizeof(data)];
291 317
292 uint16_t seq_num = Rand(); 318 const uint16_t seq_num = Rand();
293 319
294 InsertPacket(seq_num, kKeyFrame, kFirst, kNotLast, sizeof(many), many); 320 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast, sizeof(many), many));
295 InsertPacket(seq_num + 1, kDeltaFrame, kNotFirst, kNotLast, sizeof(bitstream), 321 EXPECT_TRUE(Insert(seq_num + 1, kDeltaFrame, kNotFirst, kNotLast,
296 bitstream); 322 sizeof(bitstream), bitstream));
297 InsertPacket(seq_num + 2, kDeltaFrame, kNotFirst, kNotLast, sizeof(such), 323 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kNotFirst, kNotLast,
298 such); 324 sizeof(such), such));
299 InsertPacket(seq_num + 3, kDeltaFrame, kNotFirst, kLast, sizeof(data), data); 325 EXPECT_TRUE(
326 Insert(seq_num + 3, kDeltaFrame, kNotFirst, kLast, sizeof(data), data));
300 327
301 ASSERT_EQ(1UL, frames_from_callback_.size()); 328 ASSERT_EQ(1UL, frames_from_callback_.size());
302 CheckFrame(seq_num); 329 CheckFrame(seq_num);
303 EXPECT_TRUE(frames_from_callback_[seq_num]->GetBitstream(result)); 330 EXPECT_TRUE(frames_from_callback_[seq_num]->GetBitstream(result));
304 EXPECT_EQ(memcmp(result, "many bitstream, such data", sizeof(result)), 0); 331 EXPECT_EQ(memcmp(result, "many bitstream, such data", sizeof(result)), 0);
305 } 332 }
306 333
307 TEST_F(TestPacketBuffer, FreeSlotsOnFrameDestruction) { 334 TEST_F(TestPacketBuffer, FreeSlotsOnFrameDestruction) {
308 uint16_t seq_num = Rand(); 335 const uint16_t seq_num = Rand();
309 336
310 InsertPacket(seq_num, kKeyFrame, kFirst, kNotLast); 337 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast));
311 InsertPacket(seq_num + 1, kDeltaFrame, kNotFirst, kNotLast); 338 EXPECT_TRUE(Insert(seq_num + 1, kDeltaFrame, kNotFirst, kNotLast));
312 InsertPacket(seq_num + 2, kDeltaFrame, kNotFirst, kLast); 339 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kNotFirst, kLast));
313 EXPECT_EQ(1UL, frames_from_callback_.size()); 340 EXPECT_EQ(1UL, frames_from_callback_.size());
314 CheckFrame(seq_num); 341 CheckFrame(seq_num);
315 342
316 frames_from_callback_.clear(); 343 frames_from_callback_.clear();
317 344
318 // Insert frame that fills the whole buffer. 345 // Insert frame that fills the whole buffer.
319 InsertPacket(seq_num + 3, kKeyFrame, kFirst, kNotLast); 346 EXPECT_TRUE(Insert(seq_num + 3, kKeyFrame, kFirst, kNotLast));
320 for (int i = 0; i < kMaxSize - 2; ++i) 347 for (int i = 0; i < kMaxSize - 2; ++i)
321 InsertPacket(seq_num + i + 4, kDeltaFrame, kNotFirst, kNotLast); 348 EXPECT_TRUE(Insert(seq_num + i + 4, kDeltaFrame, kNotFirst, kNotLast));
322 InsertPacket(seq_num + kMaxSize + 2, kKeyFrame, kNotFirst, kLast); 349 EXPECT_TRUE(Insert(seq_num + kMaxSize + 2, kKeyFrame, kNotFirst, kLast));
323 EXPECT_EQ(1UL, frames_from_callback_.size()); 350 EXPECT_EQ(1UL, frames_from_callback_.size());
324 CheckFrame(seq_num + 3); 351 CheckFrame(seq_num + 3);
325 } 352 }
326 353
327 TEST_F(TestPacketBuffer, Clear) { 354 TEST_F(TestPacketBuffer, Clear) {
328 uint16_t seq_num = Rand(); 355 const uint16_t seq_num = Rand();
329 356
330 InsertPacket(seq_num, kKeyFrame, kFirst, kNotLast); 357 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast));
331 InsertPacket(seq_num + 1, kDeltaFrame, kNotFirst, kNotLast); 358 EXPECT_TRUE(Insert(seq_num + 1, kDeltaFrame, kNotFirst, kNotLast));
332 InsertPacket(seq_num + 2, kDeltaFrame, kNotFirst, kLast); 359 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kNotFirst, kLast));
333 EXPECT_EQ(1UL, frames_from_callback_.size()); 360 EXPECT_EQ(1UL, frames_from_callback_.size());
334 CheckFrame(seq_num); 361 CheckFrame(seq_num);
335 362
336 packet_buffer_->Clear(); 363 packet_buffer_->Clear();
337 364
338 InsertPacket(seq_num + kStartSize, kKeyFrame, kFirst, kNotLast); 365 EXPECT_TRUE(Insert(seq_num + kStartSize, kKeyFrame, kFirst, kNotLast));
339 InsertPacket(seq_num + kStartSize + 1, kDeltaFrame, kNotFirst, kNotLast); 366 EXPECT_TRUE(
340 InsertPacket(seq_num + kStartSize + 2, kDeltaFrame, kNotFirst, kLast); 367 Insert(seq_num + kStartSize + 1, kDeltaFrame, kNotFirst, kNotLast));
368 EXPECT_TRUE(Insert(seq_num + kStartSize + 2, kDeltaFrame, kNotFirst, kLast));
341 EXPECT_EQ(2UL, frames_from_callback_.size()); 369 EXPECT_EQ(2UL, frames_from_callback_.size());
342 CheckFrame(seq_num + kStartSize); 370 CheckFrame(seq_num + kStartSize);
343 } 371 }
344 372
345 TEST_F(TestPacketBuffer, InvalidateFrameByClearing) { 373 TEST_F(TestPacketBuffer, InvalidateFrameByClearing) {
346 VCMPacket packet; 374 const uint16_t seq_num = Rand();
347 packet.frameType = kVideoFrameKey; 375
348 packet.isFirstPacket = true; 376 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kLast));
349 packet.markerBit = true;
350 packet.seqNum = Rand();
351 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
352 ASSERT_EQ(1UL, frames_from_callback_.size()); 377 ASSERT_EQ(1UL, frames_from_callback_.size());
353 378
354 packet_buffer_->Clear(); 379 packet_buffer_->Clear();
355 EXPECT_FALSE(frames_from_callback_.begin()->second->GetBitstream(nullptr)); 380 EXPECT_FALSE(frames_from_callback_.begin()->second->GetBitstream(nullptr));
356 } 381 }
357 382
358 } // namespace video_coding 383 } // namespace video_coding
359 } // namespace webrtc 384 } // 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