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

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: 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 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 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 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, InsertOldPackets) {
106 uint16_t seq_num = Rand();
danilchap 2016/10/07 18:25:37 add const: const uint16_t seq_num = Rand(); seq_nu
philipel 2016/10/18 12:22:19 Done.
107
108 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast));
109 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kFirst, kLast));
110 EXPECT_TRUE(Insert(seq_num + 1, kKeyFrame, kNotFirst, kLast));
111 ASSERT_EQ(2UL, frames_from_callback_.size());
112
113 frames_from_callback_.erase(frames_from_callback_.find(seq_num + 2));
danilchap 2016/10/07 18:25:37 that is same as frames_from_callback_.erase(seq_nu
philipel 2016/10/18 12:22:19 Done.
114 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast));
115 ASSERT_EQ(1UL, frames_from_callback_.size());
116
117 frames_from_callback_.erase(frames_from_callback_.find(seq_num));
118 ASSERT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast));
119 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kFirst, kLast));
120
121 packet_buffer_->ClearTo(seq_num + 2);
122 EXPECT_FALSE(Insert(seq_num + 2, kDeltaFrame, kFirst, kLast));
123 EXPECT_TRUE(Insert(seq_num + 3, kDeltaFrame, kFirst, kLast));
124 ASSERT_EQ(2UL, frames_from_callback_.size());
103 } 125 }
104 126
105 TEST_F(TestPacketBuffer, NackCount) { 127 TEST_F(TestPacketBuffer, NackCount) {
106 uint16_t seq_num = Rand(); 128 uint16_t seq_num = Rand();
107 129
108 VCMPacket packet; 130 VCMPacket packet;
109 packet.codec = kVideoCodecGeneric; 131 packet.codec = kVideoCodecGeneric;
110 packet.seqNum = seq_num; 132 packet.seqNum = seq_num;
111 packet.frameType = kVideoFrameKey; 133 packet.frameType = kVideoFrameKey;
112 packet.isFirstPacket = true; 134 packet.isFirstPacket = true;
113 packet.markerBit = false; 135 packet.markerBit = false;
114 packet.timesNacked = 0; 136 packet.timesNacked = 0;
115 137
116 packet_buffer_->InsertPacket(packet); 138 packet_buffer_->InsertPacket(packet);
117 139
118 packet.seqNum++; 140 packet.seqNum++;
119 packet.isFirstPacket = false; 141 packet.isFirstPacket = false;
120 packet.timesNacked = 1; 142 packet.timesNacked = 1;
121 packet_buffer_->InsertPacket(packet); 143 packet_buffer_->InsertPacket(packet);
122 144
123 packet.seqNum++; 145 packet.seqNum++;
124 packet.timesNacked = 3; 146 packet.timesNacked = 3;
125 packet_buffer_->InsertPacket(packet); 147 packet_buffer_->InsertPacket(packet);
126 148
127 packet.seqNum++; 149 packet.seqNum++;
128 packet.markerBit = true; 150 packet.markerBit = true;
129 packet.timesNacked = 1; 151 packet.timesNacked = 1;
130 packet_buffer_->InsertPacket(packet); 152 packet_buffer_->InsertPacket(packet);
131 153
132
133 ASSERT_EQ(1UL, frames_from_callback_.size()); 154 ASSERT_EQ(1UL, frames_from_callback_.size());
134 RtpFrameObject* frame = frames_from_callback_.begin()->second.get(); 155 RtpFrameObject* frame = frames_from_callback_.begin()->second.get();
135 EXPECT_EQ(3, frame->times_nacked()); 156 EXPECT_EQ(3, frame->times_nacked());
136 } 157 }
137 158
138 TEST_F(TestPacketBuffer, FrameSize) { 159 TEST_F(TestPacketBuffer, FrameSize) {
139 uint16_t seq_num = Rand(); 160 uint16_t seq_num = Rand();
140 uint8_t data[] = {1, 2, 3, 4, 5}; 161 uint8_t data[] = {1, 2, 3, 4, 5};
141 162
142 InsertPacket(seq_num, kKeyFrame, kFirst, kNotLast, 5, data); 163 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast, 5, data));
143 InsertPacket(seq_num + 1, kKeyFrame, kNotFirst, kNotLast, 5, data); 164 EXPECT_TRUE(Insert(seq_num + 1, kKeyFrame, kNotFirst, kNotLast, 5, data));
144 InsertPacket(seq_num + 2, kKeyFrame, kNotFirst, kNotLast, 5, data); 165 EXPECT_TRUE(Insert(seq_num + 2, kKeyFrame, kNotFirst, kNotLast, 5, data));
145 InsertPacket(seq_num + 3, kKeyFrame, kNotFirst, kLast, 5, data); 166 EXPECT_TRUE(Insert(seq_num + 3, kKeyFrame, kNotFirst, kLast, 5, data));
146 167
147 ASSERT_EQ(1UL, frames_from_callback_.size()); 168 ASSERT_EQ(1UL, frames_from_callback_.size());
148 EXPECT_EQ(20UL, frames_from_callback_.begin()->second->size); 169 EXPECT_EQ(20UL, frames_from_callback_.begin()->second->size);
149 } 170 }
150 171
151 TEST_F(TestPacketBuffer, ExpandBuffer) { 172 TEST_F(TestPacketBuffer, ExpandBuffer) {
152 uint16_t seq_num = Rand(); 173 uint16_t seq_num = Rand();
153 174
154 for (int i = 0; i < kStartSize + 1; ++i) { 175 for (int i = 0; i < kStartSize + 1; ++i) {
155 InsertPacket(seq_num + i, kKeyFrame, kFirst, kLast); 176 EXPECT_TRUE(Insert(seq_num + i, kKeyFrame, kFirst, kLast));
156 } 177 }
157 } 178 }
158 179
180 TEST_F(TestPacketBuffer, SingleFrameExpandsBuffer) {
181 uint16_t seq_num = Rand();
182
183 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast));
184 for (int i = 1; i < kStartSize; ++i)
185 EXPECT_TRUE(Insert(seq_num + i, kKeyFrame, kNotFirst, kNotLast));
186 EXPECT_TRUE(Insert(seq_num + kStartSize, kKeyFrame, kNotFirst, kLast));
187
188 ASSERT_EQ(1UL, frames_from_callback_.size());
189 CheckFrame(seq_num);
190 }
191
159 TEST_F(TestPacketBuffer, ExpandBufferOverflow) { 192 TEST_F(TestPacketBuffer, ExpandBufferOverflow) {
160 uint16_t seq_num = Rand(); 193 uint16_t seq_num = Rand();
161 194
162 for (int i = 0; i < kMaxSize; ++i) { 195 for (int i = 0; i < kMaxSize; ++i)
163 InsertPacket(seq_num + i, kKeyFrame, kFirst, kLast); 196 EXPECT_TRUE(Insert(seq_num + i, kKeyFrame, kFirst, kLast));
164 } 197 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 } 198 }
170 199
171 TEST_F(TestPacketBuffer, OnePacketOneFrame) { 200 TEST_F(TestPacketBuffer, OnePacketOneFrame) {
172 uint16_t seq_num = Rand(); 201 uint16_t seq_num = Rand();
173 InsertPacket(seq_num, kKeyFrame, kFirst, kLast); 202 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kLast));
174 ASSERT_EQ(1UL, frames_from_callback_.size()); 203 ASSERT_EQ(1UL, frames_from_callback_.size());
175 CheckFrame(seq_num); 204 CheckFrame(seq_num);
176 } 205 }
177 206
178 TEST_F(TestPacketBuffer, TwoPacketsTwoFrames) { 207 TEST_F(TestPacketBuffer, TwoPacketsTwoFrames) {
179 uint16_t seq_num = Rand(); 208 uint16_t seq_num = Rand();
180 209
181 InsertPacket(seq_num, kKeyFrame, kFirst, kLast); 210 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kLast));
182 InsertPacket(seq_num + 1, kKeyFrame, kFirst, kLast); 211 EXPECT_TRUE(Insert(seq_num + 1, kKeyFrame, kFirst, kLast));
183 212
184 EXPECT_EQ(2UL, frames_from_callback_.size()); 213 EXPECT_EQ(2UL, frames_from_callback_.size());
185 CheckFrame(seq_num); 214 CheckFrame(seq_num);
186 CheckFrame(seq_num + 1); 215 CheckFrame(seq_num + 1);
187 } 216 }
188 217
189 TEST_F(TestPacketBuffer, TwoPacketsOneFrames) { 218 TEST_F(TestPacketBuffer, TwoPacketsOneFrames) {
190 uint16_t seq_num = Rand(); 219 uint16_t seq_num = Rand();
191 220
192 InsertPacket(seq_num, kKeyFrame, kFirst, kNotLast); 221 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast));
193 InsertPacket(seq_num + 1, kKeyFrame, kNotFirst, kLast); 222 EXPECT_TRUE(Insert(seq_num + 1, kKeyFrame, kNotFirst, kLast));
194 223
195 EXPECT_EQ(1UL, frames_from_callback_.size()); 224 EXPECT_EQ(1UL, frames_from_callback_.size());
196 CheckFrame(seq_num); 225 CheckFrame(seq_num);
197 } 226 }
198 227
199 TEST_F(TestPacketBuffer, ThreePacketReorderingOneFrame) { 228 TEST_F(TestPacketBuffer, ThreePacketReorderingOneFrame) {
200 uint16_t seq_num = Rand(); 229 uint16_t seq_num = Rand();
201 230
202 InsertPacket(seq_num, kKeyFrame, kFirst, kNotLast); 231 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast));
203 InsertPacket(seq_num + 2, kKeyFrame, kNotFirst, kLast); 232 EXPECT_TRUE(Insert(seq_num + 2, kKeyFrame, kNotFirst, kLast));
204 InsertPacket(seq_num + 1, kKeyFrame, kNotFirst, kNotLast); 233 EXPECT_TRUE(Insert(seq_num + 1, kKeyFrame, kNotFirst, kNotLast));
205 234
206 EXPECT_EQ(1UL, frames_from_callback_.size()); 235 EXPECT_EQ(1UL, frames_from_callback_.size());
207 CheckFrame(seq_num); 236 CheckFrame(seq_num);
208 } 237 }
209 238
210 TEST_F(TestPacketBuffer, DiscardOldPacket) {
211 VCMPacket packet;
212 packet.seqNum = Rand();
213 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
214 packet.seqNum += 2;
215 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
216
217 for (int i = 3; i < kMaxSize; ++i) {
218 ++packet.seqNum;
219 EXPECT_TRUE(packet_buffer_->InsertPacket(packet));
220 }
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) { 239 TEST_F(TestPacketBuffer, Frames) {
253 uint16_t seq_num = Rand(); 240 uint16_t seq_num = Rand();
254 241
255 InsertPacket(seq_num, kKeyFrame, kFirst, kLast); 242 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kLast));
256 InsertPacket(seq_num + 1, kDeltaFrame, kFirst, kLast); 243 EXPECT_TRUE(Insert(seq_num + 1, kDeltaFrame, kFirst, kLast));
257 InsertPacket(seq_num + 2, kDeltaFrame, kFirst, kLast); 244 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kFirst, kLast));
258 InsertPacket(seq_num + 3, kDeltaFrame, kFirst, kLast); 245 EXPECT_TRUE(Insert(seq_num + 3, kDeltaFrame, kFirst, kLast));
259 246
260 ASSERT_EQ(4UL, frames_from_callback_.size()); 247 ASSERT_EQ(4UL, frames_from_callback_.size());
261 CheckFrame(seq_num); 248 CheckFrame(seq_num);
262 CheckFrame(seq_num + 1); 249 CheckFrame(seq_num + 1);
263 CheckFrame(seq_num + 2); 250 CheckFrame(seq_num + 2);
264 CheckFrame(seq_num + 3); 251 CheckFrame(seq_num + 3);
265 } 252 }
266 253
254 TEST_F(TestPacketBuffer, ClearSinglePacket) {
255 uint16_t seq_num = Rand();
256
257 for (int i = 0; i < kMaxSize; ++i)
258 EXPECT_TRUE(Insert(seq_num + i, kDeltaFrame, kFirst, kLast));
259
260 packet_buffer_->ClearTo(seq_num);
261 EXPECT_TRUE(Insert(seq_num + kMaxSize, kDeltaFrame, kFirst, kLast));
262 }
263
264 TEST_F(TestPacketBuffer, OneIncompleteFrame) {
265 uint16_t seq_num = Rand();
266
267 EXPECT_TRUE(Insert(seq_num, kDeltaFrame, kFirst, kNotLast));
268 EXPECT_TRUE(Insert(seq_num + 1, kDeltaFrame, kNotFirst, kLast));
269 EXPECT_TRUE(Insert(seq_num - 1, kDeltaFrame, kNotFirst, kLast));
270
271 ASSERT_EQ(1UL, frames_from_callback_.size());
272 CheckFrame(seq_num);
273 }
274
275 TEST_F(TestPacketBuffer, TwoIncompleteFramesFullBuffer) {
276 uint16_t seq_num = Rand();
277
278 for (int i = 1; i < kMaxSize - 1; ++i)
279 EXPECT_TRUE(Insert(seq_num + i, kDeltaFrame, kNotFirst, kNotLast));
280 EXPECT_TRUE(Insert(seq_num, kDeltaFrame, kFirst, kNotLast));
281 EXPECT_TRUE(Insert(seq_num - 1, kDeltaFrame, kNotFirst, kLast));
282
283 ASSERT_EQ(0UL, frames_from_callback_.size());
284 }
285
267 TEST_F(TestPacketBuffer, FramesReordered) { 286 TEST_F(TestPacketBuffer, FramesReordered) {
268 uint16_t seq_num = Rand(); 287 uint16_t seq_num = Rand();
269 288
270 InsertPacket(seq_num + 1, kDeltaFrame, kFirst, kLast); 289 EXPECT_TRUE(Insert(seq_num + 1, kDeltaFrame, kFirst, kLast));
271 InsertPacket(seq_num, kKeyFrame, kFirst, kLast); 290 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kLast));
272 InsertPacket(seq_num + 3, kDeltaFrame, kFirst, kLast); 291 EXPECT_TRUE(Insert(seq_num + 3, kDeltaFrame, kFirst, kLast));
273 InsertPacket(seq_num + 2, kDeltaFrame, kFirst, kLast); 292 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kFirst, kLast));
274 293
275 ASSERT_EQ(4UL, frames_from_callback_.size()); 294 ASSERT_EQ(4UL, frames_from_callback_.size());
276 CheckFrame(seq_num); 295 CheckFrame(seq_num);
277 CheckFrame(seq_num + 1); 296 CheckFrame(seq_num + 1);
278 CheckFrame(seq_num + 2); 297 CheckFrame(seq_num + 2);
279 CheckFrame(seq_num + 3); 298 CheckFrame(seq_num + 3);
280 } 299 }
281 300
282 TEST_F(TestPacketBuffer, GetBitstreamFromFrame) { 301 TEST_F(TestPacketBuffer, GetBitstreamFromFrame) {
283 // "many bitstream, such data" with null termination. 302 // "many bitstream, such data" with null termination.
284 uint8_t many[] = {0x6d, 0x61, 0x6e, 0x79, 0x20}; 303 uint8_t many[] = {0x6d, 0x61, 0x6e, 0x79, 0x20};
285 uint8_t bitstream[] = {0x62, 0x69, 0x74, 0x73, 0x74, 0x72, 304 uint8_t bitstream[] = {0x62, 0x69, 0x74, 0x73, 0x74, 0x72,
286 0x65, 0x61, 0x6d, 0x2c, 0x20}; 305 0x65, 0x61, 0x6d, 0x2c, 0x20};
287 uint8_t such[] = {0x73, 0x75, 0x63, 0x68, 0x20}; 306 uint8_t such[] = {0x73, 0x75, 0x63, 0x68, 0x20};
288 uint8_t data[] = {0x64, 0x61, 0x74, 0x61, 0x0}; 307 uint8_t data[] = {0x64, 0x61, 0x74, 0x61, 0x0};
289 uint8_t 308 uint8_t
290 result[sizeof(many) + sizeof(bitstream) + sizeof(such) + sizeof(data)]; 309 result[sizeof(many) + sizeof(bitstream) + sizeof(such) + sizeof(data)];
291 310
292 uint16_t seq_num = Rand(); 311 uint16_t seq_num = Rand();
293 312
294 InsertPacket(seq_num, kKeyFrame, kFirst, kNotLast, sizeof(many), many); 313 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast, sizeof(many), many));
295 InsertPacket(seq_num + 1, kDeltaFrame, kNotFirst, kNotLast, sizeof(bitstream), 314 EXPECT_TRUE(Insert(seq_num + 1, kDeltaFrame, kNotFirst, kNotLast,
296 bitstream); 315 sizeof(bitstream), bitstream));
297 InsertPacket(seq_num + 2, kDeltaFrame, kNotFirst, kNotLast, sizeof(such), 316 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kNotFirst, kNotLast,
298 such); 317 sizeof(such), such));
299 InsertPacket(seq_num + 3, kDeltaFrame, kNotFirst, kLast, sizeof(data), data); 318 EXPECT_TRUE(
319 Insert(seq_num + 3, kDeltaFrame, kNotFirst, kLast, sizeof(data), data));
300 320
301 ASSERT_EQ(1UL, frames_from_callback_.size()); 321 ASSERT_EQ(1UL, frames_from_callback_.size());
302 CheckFrame(seq_num); 322 CheckFrame(seq_num);
303 EXPECT_TRUE(frames_from_callback_[seq_num]->GetBitstream(result)); 323 EXPECT_TRUE(frames_from_callback_[seq_num]->GetBitstream(result));
304 EXPECT_EQ(memcmp(result, "many bitstream, such data", sizeof(result)), 0); 324 EXPECT_EQ(memcmp(result, "many bitstream, such data", sizeof(result)), 0);
305 } 325 }
306 326
307 TEST_F(TestPacketBuffer, FreeSlotsOnFrameDestruction) { 327 TEST_F(TestPacketBuffer, FreeSlotsOnFrameDestruction) {
308 uint16_t seq_num = Rand(); 328 uint16_t seq_num = Rand();
309 329
310 InsertPacket(seq_num, kKeyFrame, kFirst, kNotLast); 330 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast));
311 InsertPacket(seq_num + 1, kDeltaFrame, kNotFirst, kNotLast); 331 EXPECT_TRUE(Insert(seq_num + 1, kDeltaFrame, kNotFirst, kNotLast));
312 InsertPacket(seq_num + 2, kDeltaFrame, kNotFirst, kLast); 332 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kNotFirst, kLast));
313 EXPECT_EQ(1UL, frames_from_callback_.size()); 333 EXPECT_EQ(1UL, frames_from_callback_.size());
314 CheckFrame(seq_num); 334 CheckFrame(seq_num);
315 335
316 frames_from_callback_.clear(); 336 frames_from_callback_.clear();
317 337
318 // Insert frame that fills the whole buffer. 338 // Insert frame that fills the whole buffer.
319 InsertPacket(seq_num + 3, kKeyFrame, kFirst, kNotLast); 339 EXPECT_TRUE(Insert(seq_num + 3, kKeyFrame, kFirst, kNotLast));
320 for (int i = 0; i < kMaxSize - 2; ++i) 340 for (int i = 0; i < kMaxSize - 2; ++i)
321 InsertPacket(seq_num + i + 4, kDeltaFrame, kNotFirst, kNotLast); 341 EXPECT_TRUE(Insert(seq_num + i + 4, kDeltaFrame, kNotFirst, kNotLast));
322 InsertPacket(seq_num + kMaxSize + 2, kKeyFrame, kNotFirst, kLast); 342 EXPECT_TRUE(Insert(seq_num + kMaxSize + 2, kKeyFrame, kNotFirst, kLast));
323 EXPECT_EQ(1UL, frames_from_callback_.size()); 343 EXPECT_EQ(1UL, frames_from_callback_.size());
324 CheckFrame(seq_num + 3); 344 CheckFrame(seq_num + 3);
325 } 345 }
326 346
327 TEST_F(TestPacketBuffer, Clear) { 347 TEST_F(TestPacketBuffer, Clear) {
328 uint16_t seq_num = Rand(); 348 uint16_t seq_num = Rand();
329 349
330 InsertPacket(seq_num, kKeyFrame, kFirst, kNotLast); 350 EXPECT_TRUE(Insert(seq_num, kKeyFrame, kFirst, kNotLast));
331 InsertPacket(seq_num + 1, kDeltaFrame, kNotFirst, kNotLast); 351 EXPECT_TRUE(Insert(seq_num + 1, kDeltaFrame, kNotFirst, kNotLast));
332 InsertPacket(seq_num + 2, kDeltaFrame, kNotFirst, kLast); 352 EXPECT_TRUE(Insert(seq_num + 2, kDeltaFrame, kNotFirst, kLast));
333 EXPECT_EQ(1UL, frames_from_callback_.size()); 353 EXPECT_EQ(1UL, frames_from_callback_.size());
334 CheckFrame(seq_num); 354 CheckFrame(seq_num);
335 355
336 packet_buffer_->Clear(); 356 packet_buffer_->Clear();
337 357
338 InsertPacket(seq_num + kStartSize, kKeyFrame, kFirst, kNotLast); 358 EXPECT_TRUE(Insert(seq_num + kStartSize, kKeyFrame, kFirst, kNotLast));
339 InsertPacket(seq_num + kStartSize + 1, kDeltaFrame, kNotFirst, kNotLast); 359 EXPECT_TRUE(
340 InsertPacket(seq_num + kStartSize + 2, kDeltaFrame, kNotFirst, kLast); 360 Insert(seq_num + kStartSize + 1, kDeltaFrame, kNotFirst, kNotLast));
361 EXPECT_TRUE(Insert(seq_num + kStartSize + 2, kDeltaFrame, kNotFirst, kLast));
341 EXPECT_EQ(2UL, frames_from_callback_.size()); 362 EXPECT_EQ(2UL, frames_from_callback_.size());
342 CheckFrame(seq_num + kStartSize); 363 CheckFrame(seq_num + kStartSize);
343 } 364 }
344 365
345 TEST_F(TestPacketBuffer, InvalidateFrameByClearing) { 366 TEST_F(TestPacketBuffer, InvalidateFrameByClearing) {
346 VCMPacket packet; 367 uint16_t seq_num = Rand();
347 packet.frameType = kVideoFrameKey; 368
348 packet.isFirstPacket = true; 369 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()); 370 ASSERT_EQ(1UL, frames_from_callback_.size());
353 371
354 packet_buffer_->Clear(); 372 packet_buffer_->Clear();
355 EXPECT_FALSE(frames_from_callback_.begin()->second->GetBitstream(nullptr)); 373 EXPECT_FALSE(frames_from_callback_.begin()->second->GetBitstream(nullptr));
356 } 374 }
357 375
358 } // namespace video_coding 376 } // namespace video_coding
359 } // namespace webrtc 377 } // 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