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

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_format_vp9_unittest.cc

Issue 1232023006: Add support for VP9 packetization/depacketization. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: update comments Created 5 years, 5 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
(Empty)
1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include <vector>
12
13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "webrtc/modules/rtp_rtcp/source/rtp_format_vp9.h"
16 #include "webrtc/typedefs.h"
17
18 namespace webrtc {
19 namespace {
20 void VerifyHeader(const RTPVideoHeaderVP9& expected,
21 const RTPVideoHeaderVP9& actual) {
22 EXPECT_EQ(expected.inter_layer_predicted, actual.inter_layer_predicted);
23 EXPECT_EQ(expected.inter_pic_predicted, actual.inter_pic_predicted);
24 EXPECT_EQ(expected.flexible_mode, actual.flexible_mode);
25 EXPECT_EQ(expected.beginning_of_frame, actual.beginning_of_frame);
26 EXPECT_EQ(expected.end_of_frame, actual.end_of_frame);
27 EXPECT_EQ(expected.ss_data_available, actual.ss_data_available);
28 EXPECT_EQ(expected.picture_id, actual.picture_id);
29 EXPECT_EQ(expected.max_picture_id, actual.max_picture_id);
30 EXPECT_EQ(expected.temporal_idx == kNoTemporalIdx ? 0 : expected.temporal_idx,
31 actual.temporal_idx);
32 EXPECT_EQ(expected.spatial_idx == kNoSpatialIdx ? 0 : expected.spatial_idx,
33 actual.spatial_idx);
34 EXPECT_EQ(expected.gof_idx, actual.gof_idx);
35 EXPECT_EQ(expected.tl0_pic_idx, actual.tl0_pic_idx);
36 EXPECT_EQ(expected.temporal_up_switch, actual.temporal_up_switch);
37
38 EXPECT_EQ(expected.num_ref_pics, actual.num_ref_pics);
39 for (uint8_t i = 0; i < expected.num_ref_pics; ++i) {
40 EXPECT_EQ(expected.pid_diff[i], actual.pid_diff[i]);
41 }
42 if (expected.ss_data_available) {
43 EXPECT_EQ(expected.spatial_layer_resolution_present,
44 actual.spatial_layer_resolution_present);
45 EXPECT_EQ(expected.num_spatial_layers, actual.num_spatial_layers);
46 if (expected.spatial_layer_resolution_present) {
47 for (size_t i = 0; i < expected.num_spatial_layers; i++) {
48 EXPECT_EQ(expected.width[i], actual.width[i]);
49 EXPECT_EQ(expected.height[i], actual.height[i]);
50 }
51 }
52 EXPECT_EQ(expected.gof.num_frames_in_gof, actual.gof.num_frames_in_gof);
53 for (size_t i = 0; i < expected.gof.num_frames_in_gof; i++) {
54 EXPECT_EQ(expected.gof.temporal_up_switch[i],
55 actual.gof.temporal_up_switch[i]);
56 EXPECT_EQ(expected.gof.temporal_idx[i], actual.gof.temporal_idx[i]);
57 EXPECT_EQ(expected.gof.num_ref_pics[i], actual.gof.num_ref_pics[i]);
58 for (size_t j = 0; j < expected.gof.num_ref_pics[i]; j++) {
59 EXPECT_EQ(expected.gof.pid_diff[i][j], actual.gof.pid_diff[i][j]);
60 }
61 }
62 }
63 }
64
65 void VerifyPayload(const RtpDepacketizer::ParsedPayload& parsed,
66 const uint8_t* payload,
67 size_t payload_length) {
68 EXPECT_EQ(payload, parsed.payload);
69 EXPECT_EQ(payload_length, parsed.payload_length);
70 EXPECT_THAT(std::vector<uint8_t>(parsed.payload,
71 parsed.payload + parsed.payload_length),
72 ::testing::ElementsAreArray(payload, payload_length));
73 }
74
75 void ParseAndCheckPacket(const uint8_t* packet,
76 const RTPVideoHeaderVP9& expected,
77 size_t expected_hdr_length,
78 size_t expected_length) {
79 rtc::scoped_ptr<RtpDepacketizer> depacketizer(new RtpDepacketizerVp9());
80 RtpDepacketizer::ParsedPayload parsed;
81 ASSERT_TRUE(depacketizer->Parse(&parsed, packet, expected_length));
82 // TODO(asapersson): Add when type is added.
83 // EXPECT_EQ(kRtpVideoVp9, parsed.type.Video.codec);
84 VerifyHeader(expected, parsed.type.Video.codecHeader.VP9);
85 const size_t kExpectedPayloadLength = expected_length - expected_hdr_length;
86 VerifyPayload(parsed, packet + expected_hdr_length, kExpectedPayloadLength);
87 }
88 } // namespace
89
90 // Payload descriptor for flexible mode
91 // 0 1 2 3 4 5 6 7
92 // +-+-+-+-+-+-+-+-+
93 // |I|P|L|F|B|E|V|-| (REQUIRED)
94 // +-+-+-+-+-+-+-+-+
95 // I: |M| PICTURE ID | (RECOMMENDED)
96 // +-+-+-+-+-+-+-+-+
97 // M: | EXTENDED PID | (RECOMMENDED)
98 // +-+-+-+-+-+-+-+-+
99 // L: | T |U| S |D| (CONDITIONALLY RECOMMENDED)
100 // +-+-+-+-+-+-+-+-+ -|
101 // P,F: | P_DIFF |X|N| (CONDITIONALLY RECOMMENDED) .
102 // +-+-+-+-+-+-+-+-+ . up to 3 times
103 // X: |EXTENDED P_DIFF| (OPTIONAL) .
104 // +-+-+-+-+-+-+-+-+ -|
105 // V: | SS |
106 // | .. |
107 // +-+-+-+-+-+-+-+-+
108 //
109 // Payload descriptor for non-flexible mode
110 // 0 1 2 3 4 5 6 7
111 // +-+-+-+-+-+-+-+-+
112 // |I|P|L|F|B|E|V|-| (REQUIRED)
113 // +-+-+-+-+-+-+-+-+
114 // I: |M| PICTURE ID | (RECOMMENDED)
115 // +-+-+-+-+-+-+-+-+
116 // M: | EXTENDED PID | (RECOMMENDED)
117 // +-+-+-+-+-+-+-+-+
118 // L: |GOF_IDX| S |D| (CONDITIONALLY RECOMMENDED)
119 // +-+-+-+-+-+-+-+-+
120 // | TL0PICIDX | (CONDITIONALLY REQUIRED)
121 // +-+-+-+-+-+-+-+-+
122 // V: | SS |
123 // | .. |
124 // +-+-+-+-+-+-+-+-+
125
126 class RtpPacketizerVp9Test : public ::testing::Test {
127 protected:
128 RtpPacketizerVp9Test() {}
129 virtual void SetUp() {
130 expected_.InitRTPVideoHeaderVP9();
131 // Always input one layer frame at a time.
132 expected_.beginning_of_frame = true;
133 expected_.end_of_frame = true;
134 }
135
136 rtc::scoped_ptr<uint8_t[]> packet_;
137 rtc::scoped_ptr<uint8_t[]> payload_;
138 size_t payload_size_;
139 size_t payload_pos_;
140 RTPVideoHeaderVP9 expected_;
141 rtc::scoped_ptr<RtpPacketizerVp9> packetizer_;
142
143 void Init(size_t payload_size, size_t packet_size) {
144 payload_.reset(new uint8_t[payload_size]);
145 memset(payload_.get(), 7, payload_size);
146 payload_size_ = payload_size;
147 payload_pos_ = 0;
148 packetizer_.reset(new RtpPacketizerVp9(expected_, packet_size));
149 packetizer_->SetPayloadData(payload_.get(), payload_size_, NULL);
150
151 const int kMaxPayloadDescriptorLength = 100;
152 packet_.reset(new uint8_t[payload_size_ + kMaxPayloadDescriptorLength]);
153 }
154
155 void CheckPayload(const uint8_t* packet,
156 size_t start_pos,
157 size_t end_pos,
158 bool last) {
159 for (size_t i = start_pos; i < end_pos; ++i) {
160 EXPECT_EQ(packet[i], payload_[payload_pos_++]);
161 }
162 EXPECT_EQ(last, payload_pos_ == payload_size_);
163 }
164
165 void CreateParseAndCheckPackets(const size_t* expected_hdr_sizes,
166 const size_t* expected_sizes,
167 size_t expected_num_packets) {
168 ASSERT_TRUE(packetizer_.get() != NULL);
169 size_t length = 0;
170 bool last = false;
171 if (expected_num_packets == 0) {
172 EXPECT_FALSE(packetizer_->NextPacket(packet_.get(), &length, &last));
173 return;
174 }
175 for (size_t i = 0; i < expected_num_packets; ++i) {
176 EXPECT_TRUE(packetizer_->NextPacket(packet_.get(), &length, &last));
177 EXPECT_EQ(expected_sizes[i], length);
178 RTPVideoHeaderVP9 hdr = expected_;
179 hdr.beginning_of_frame = (i == 0);
180 hdr.end_of_frame = last;
181 ParseAndCheckPacket(packet_.get(), hdr, expected_hdr_sizes[i], length);
182 CheckPayload(packet_.get(), expected_hdr_sizes[i], length, last);
183 }
184 EXPECT_TRUE(last);
185 }
186 };
187
188 TEST_F(RtpPacketizerVp9Test, TestEqualSizedMode_OnePacket) {
189 const size_t kFrameSize = 25;
190 const size_t kPacketSize = 26;
191 Init(kFrameSize, kPacketSize);
192
193 // One packet:
194 // I:0, P:0, L:0, F:0, B:1, E:1, V:0 (1hdr + 25 payload)
195 const size_t kExpectedHdrSizes[] = {1};
196 const size_t kExpectedSizes[] = {26};
197 const size_t kExpectedNum = GTEST_ARRAY_SIZE_(kExpectedSizes);
198 CreateParseAndCheckPackets(kExpectedHdrSizes, kExpectedSizes, kExpectedNum);
199 }
200
201 TEST_F(RtpPacketizerVp9Test, TestEqualSizedMode_TwoPackets) {
202 const size_t kFrameSize = 27;
203 const size_t kPacketSize = 27;
204 Init(kFrameSize, kPacketSize);
205
206 // Two packets:
207 // I:0, P:0, L:0, F:0, B:1, E:0, V:0 (1hdr + 14 payload)
208 // I:0, P:0, L:0, F:0, B:0, E:1, V:0 (1hdr + 13 payload)
209 const size_t kExpectedHdrSizes[] = {1, 1};
210 const size_t kExpectedSizes[] = {15, 14};
211 const size_t kExpectedNum = GTEST_ARRAY_SIZE_(kExpectedSizes);
212 CreateParseAndCheckPackets(kExpectedHdrSizes, kExpectedSizes, kExpectedNum);
213 }
214
215 TEST_F(RtpPacketizerVp9Test, TestTooShortBufferToFitPayload) {
216 const size_t kFrameSize = 1;
217 const size_t kPacketSize = 1;
218 Init(kFrameSize, kPacketSize); // 1hdr + 1 payload
219
220 const size_t kExpectedNum = 0;
221 CreateParseAndCheckPackets(NULL, NULL, kExpectedNum);
222 }
223
224 TEST_F(RtpPacketizerVp9Test, TestOneBytePictureId) {
225 const size_t kFrameSize = 30;
226 const size_t kPacketSize = 12;
227
228 expected_.picture_id = kMaxOneBytePictureId; // 2 byte payload descriptor
229 expected_.max_picture_id = kMaxOneBytePictureId;
230 Init(kFrameSize, kPacketSize);
231
232 // Three packets:
233 // I:1, P:0, L:0, F:0, B:1, E:0, V:0 (2hdr + 10 payload)
234 // I:1, P:0, L:0, F:0, B:0, E:0, V:0 (2hdr + 10 payload)
235 // I:1, P:0, L:0, F:0, B:0, E:1, V:0 (2hdr + 10 payload)
236 const size_t kExpectedHdrSizes[] = {2, 2, 2};
237 const size_t kExpectedSizes[] = {12, 12, 12};
238 const size_t kExpectedNum = GTEST_ARRAY_SIZE_(kExpectedSizes);
239 CreateParseAndCheckPackets(kExpectedHdrSizes, kExpectedSizes, kExpectedNum);
240 }
241
242 TEST_F(RtpPacketizerVp9Test, TestTwoBytePictureId) {
243 const size_t kFrameSize = 31;
244 const size_t kPacketSize = 13;
245
246 expected_.picture_id = kMaxTwoBytePictureId; // 3 byte payload descriptor
247 Init(kFrameSize, kPacketSize);
248
249 // Four packets:
250 // I:1, P:0, L:0, F:0, B:1, E:0, V:0 (3hdr + 8 payload)
251 // I:1, P:0, L:0, F:0, B:0, E:0, V:0 (3hdr + 8 payload)
252 // I:1, P:0, L:0, F:0, B:0, E:0, V:0 (3hdr + 8 payload)
253 // I:1, P:0, L:0, F:0, B:0, E:1, V:0 (3hdr + 7 payload)
254 const size_t kExpectedHdrSizes[] = {3, 3, 3, 3};
255 const size_t kExpectedSizes[] = {11, 11, 11, 10};
256 const size_t kExpectedNum = GTEST_ARRAY_SIZE_(kExpectedSizes);
257 CreateParseAndCheckPackets(kExpectedHdrSizes, kExpectedSizes, kExpectedNum);
258 }
259
260 TEST_F(RtpPacketizerVp9Test, TestLayerInfoWithNonFlexibleMode) {
261 const size_t kFrameSize = 30;
262 const size_t kPacketSize = 25;
263
264 expected_.gof_idx = 3;
265 expected_.spatial_idx = 2;
266 expected_.inter_layer_predicted = true; // D
267 expected_.tl0_pic_idx = 117;
268 Init(kFrameSize, kPacketSize);
269
270 // Two packets:
271 // | I:0, P:0, L:1, F:0, B:1, E:0, V:0 | (3hdr + 15 payload)
272 // L: | GOF_IDX:3, S:2, D:1 | TL0PICIDX:117 |
273 // | I:0, P:0, L:1, F:0, B:0, E:1, V:0 | (3hdr + 15 payload)
274 // L: | GOF_IDX:3, S:2, D:1 | TL0PICIDX:117 |
275 const size_t kExpectedHdrSizes[] = {3, 3};
276 const size_t kExpectedSizes[] = {18, 18};
277 const size_t kExpectedNum = GTEST_ARRAY_SIZE_(kExpectedSizes);
278 CreateParseAndCheckPackets(kExpectedHdrSizes, kExpectedSizes, kExpectedNum);
279 }
280
281 TEST_F(RtpPacketizerVp9Test, TestLayerInfoWithFlexibleMode) {
282 const size_t kFrameSize = 21;
283 const size_t kPacketSize = 23;
284
285 expected_.flexible_mode = true;
286 expected_.temporal_idx = 3;
287 expected_.temporal_up_switch = true; // U
288 expected_.spatial_idx = 2;
289 expected_.inter_layer_predicted = false; // D
290 Init(kFrameSize, kPacketSize);
291
292 // One packet:
293 // I:0, P:0, L:1, F:1, B:1, E:1, V:0 (2hdr + 21 payload)
294 // L: T:3, U:1, S:2, D:0
295 const size_t kExpectedHdrSizes[] = {2};
296 const size_t kExpectedSizes[] = {23};
297 const size_t kExpectedNum = GTEST_ARRAY_SIZE_(kExpectedSizes);
298 CreateParseAndCheckPackets(kExpectedHdrSizes, kExpectedSizes, kExpectedNum);
299 }
300
301 TEST_F(RtpPacketizerVp9Test, TestRefIdx) {
302 const size_t kFrameSize = 16;
303 const size_t kPacketSize = 22;
304
305 expected_.inter_pic_predicted = true; // P
306 expected_.flexible_mode = true; // F
307 expected_.picture_id = 100;
308 expected_.num_ref_pics = 2;
309 expected_.pid_diff[0] = 3;
310 expected_.pid_diff[1] = 1171;
311 Init(kFrameSize, kPacketSize);
312
313 // Two packets:
314 // I:1, P:1, L:0, F:1, B:1, E:1, V:0 (6hdr + 16 payload)
315 // I: 100 (2 bytes)
316 // P,F: P_DIFF:3, X:0, N:1
317 // P_DIFF:1171, X:1, N:0 (2 bytes)
318 const size_t kExpectedHdrSizes[] = {6};
319 const size_t kExpectedSizes[] = {22};
320 const size_t kExpectedNum = GTEST_ARRAY_SIZE_(kExpectedSizes);
321 CreateParseAndCheckPackets(kExpectedHdrSizes, kExpectedSizes, kExpectedNum);
322 }
323
324 TEST_F(RtpPacketizerVp9Test, TestRefIdxFailsWithoutPictureId) {
325 const size_t kFrameSize = 16;
326 const size_t kPacketSize = 22;
327
328 expected_.inter_pic_predicted = true;
329 expected_.flexible_mode = true;
330 expected_.num_ref_pics = 1;
331 expected_.pid_diff[0] = 3;
332 Init(kFrameSize, kPacketSize);
333
334 const size_t kExpectedNum = 0;
335 CreateParseAndCheckPackets(NULL, NULL, kExpectedNum);
336 }
337
338 TEST_F(RtpPacketizerVp9Test, TestSsDataWithoutSpatialResolutionPresent) {
339 const size_t kFrameSize = 21;
340 const size_t kPacketSize = 25;
341
342 expected_.ss_data_available = true;
343 expected_.num_spatial_layers = 1;
344 expected_.spatial_layer_resolution_present = false;
345 expected_.gof.num_frames_in_gof = 1;
346 expected_.gof.temporal_idx[0] = 0;
347 expected_.gof.temporal_up_switch[0] = true;
348 expected_.gof.num_ref_pics[0] = 1;
349 expected_.gof.pid_diff[0][0] = 4;
350 Init(kFrameSize, kPacketSize);
351
352 // One packet:
353 // I:0, P:0, L:0, F:0, B:1, E:1, V:1 (4hdr + 21 payload)
354 // N_S:0, Y:0, N_G:0
355 // T:0, U:1, R:1 | P_DIFF[0][0]:4
356 const size_t kExpectedHdrSizes[] = {4};
357 const size_t kExpectedSizes[] = {25};
358 const size_t kExpectedNum = GTEST_ARRAY_SIZE_(kExpectedSizes);
359 CreateParseAndCheckPackets(kExpectedHdrSizes, kExpectedSizes, kExpectedNum);
360 }
361
362 TEST_F(RtpPacketizerVp9Test, TestSsData) {
363 const size_t kFrameSize = 21;
364 const size_t kPacketSize = 39;
365
366 expected_.ss_data_available = true;
367 expected_.num_spatial_layers = 2;
368 expected_.spatial_layer_resolution_present = true;
369 expected_.width[0] = 640;
370 expected_.width[1] = 1280;
371 expected_.height[0] = 360;
372 expected_.height[1] = 720;
373 expected_.gof.num_frames_in_gof = 3;
374 expected_.gof.temporal_idx[0] = 0;
375 expected_.gof.temporal_idx[1] = 1;
376 expected_.gof.temporal_idx[2] = 2;
377 expected_.gof.temporal_up_switch[0] = true;
378 expected_.gof.temporal_up_switch[1] = true;
379 expected_.gof.temporal_up_switch[2] = false;
380 expected_.gof.num_ref_pics[0] = 0;
381 expected_.gof.num_ref_pics[1] = 3;
382 expected_.gof.num_ref_pics[2] = 2;
383 expected_.gof.pid_diff[1][0] = 5;
384 expected_.gof.pid_diff[1][1] = 6;
385 expected_.gof.pid_diff[1][2] = 7;
386 expected_.gof.pid_diff[2][0] = 8;
387 expected_.gof.pid_diff[2][1] = 9;
388 Init(kFrameSize, kPacketSize);
389
390 // One packet:
391 // I:0, P:0, L:0, F:0, B:1, E:1, V:1 (18hdr + 21 payload)
392 // N_S:1, Y:1, N_G:2
393 // WIDTH:640 // 2 bytes
394 // HEIGHT:360 // 2 bytes
395 // WIDTH:1280 // 2 bytes
396 // HEIGHT:720 // 2 bytes
397 // T:0, U:1, R:0
398 // T:1, U:1, R:3 | P_DIFF[1][0]:5 | P_DIFF[1][1]:6 | P_DIFF[1][2]:7
399 // T:2, U:0, R:2 | P_DIFF[2][0]:8 | P_DIFF[2][0]:9
400 const size_t kExpectedHdrSizes[] = {18};
401 const size_t kExpectedSizes[] = {39};
402 const size_t kExpectedNum = GTEST_ARRAY_SIZE_(kExpectedSizes);
403 CreateParseAndCheckPackets(kExpectedHdrSizes, kExpectedSizes, kExpectedNum);
404 }
405
406
407 class RtpDepacketizerVp9Test : public ::testing::Test {
408 protected:
409 RtpDepacketizerVp9Test()
410 : depacketizer_(new RtpDepacketizerVp9()) {}
411
412 virtual void SetUp() {
413 expected_.InitRTPVideoHeaderVP9();
414 }
415
416 RTPVideoHeaderVP9 expected_;
417 rtc::scoped_ptr<RtpDepacketizer> depacketizer_;
418 };
419
420 TEST_F(RtpDepacketizerVp9Test, ParseBasicHeader) {
421 const uint8_t kHeaderLength = 1;
422 uint8_t packet[4] = {0};
423 packet[0] = 0x0C; // I:0 P:0 L:0 F:0 B:1 E:1 V:0 R:0
424 expected_.beginning_of_frame = true;
425 expected_.end_of_frame = true;
426 ParseAndCheckPacket(packet, expected_, kHeaderLength, sizeof(packet));
427 }
428
429 TEST_F(RtpDepacketizerVp9Test, ParseOneBytePictureId) {
430 const uint8_t kHeaderLength = 2;
431 uint8_t packet[10] = {0};
432 packet[0] = 0x80; // I:1 P:0 L:0 F:0 B:0 E:0 V:0 R:0
433 packet[1] = kMaxOneBytePictureId;
434
435 expected_.picture_id = kMaxOneBytePictureId;
436 expected_.max_picture_id = kMaxOneBytePictureId;
437 ParseAndCheckPacket(packet, expected_, kHeaderLength, sizeof(packet));
438 }
439
440 TEST_F(RtpDepacketizerVp9Test, ParseTwoBytePictureId) {
441 const uint8_t kHeaderLength = 3;
442 uint8_t packet[10] = {0};
443 packet[0] = 0x80; // I:1 P:0 L:0 F:0 B:0 E:0 V:0 R:0
444 packet[1] = 0x80 | ((kMaxTwoBytePictureId >> 8) & 0x7F);
445 packet[2] = kMaxTwoBytePictureId & 0xFF;
446
447 expected_.picture_id = kMaxTwoBytePictureId;
448 expected_.max_picture_id = kMaxTwoBytePictureId;
449 ParseAndCheckPacket(packet, expected_, kHeaderLength, sizeof(packet));
450 }
451
452 TEST_F(RtpDepacketizerVp9Test, ParseLayerInfoWithNonFlexibleMode) {
453 const uint8_t kHeaderLength = 3;
454 const uint8_t kGofIdx = 7;
455 const uint8_t kSpatialIdx = 1;
456 const uint8_t kDbit = 1;
457 const uint8_t kTl0PicIdx = 17;
458 uint8_t packet[13] = {0};
459 packet[0] = 0x20; // I:0 P:0 L:1 F:0 B:0 E:0 V:0 R:0
460 packet[1] = (kGofIdx << 4) | (kSpatialIdx << 1) | kDbit; // GOF_IDX:7 S:1 D:1
461 packet[2] = kTl0PicIdx; // TL0PICIDX:17
462
463 expected_.gof_idx = kGofIdx;
464 expected_.spatial_idx = kSpatialIdx;
465 expected_.inter_layer_predicted = kDbit ? true : false;
466 expected_.tl0_pic_idx = kTl0PicIdx;
467 ParseAndCheckPacket(packet, expected_, kHeaderLength, sizeof(packet));
468 }
469
470 TEST_F(RtpDepacketizerVp9Test, ParseLayerInfoWithFlexibleMode) {
471 const uint8_t kHeaderLength = 2;
472 const uint8_t kTemporalIdx = 2;
473 const uint8_t kUbit = 1;
474 const uint8_t kSpatialIdx = 0;
475 const uint8_t kDbit = 0;
476 uint8_t packet[13] = {0};
477 packet[0] = 0x38; // I:0 P:0 L:1 F:1 B:1 E:0 V:0 R:0
478 packet[1] = (kTemporalIdx << 5) | (kUbit << 4) | (kSpatialIdx << 1) | kDbit;
479
480 // I:0 P:0 L:1 F:1 B:1 E:0 V:0
481 // L: T:2 U:1 S:0 D:0
482 expected_.beginning_of_frame = true;
483 expected_.flexible_mode = true;
484 expected_.temporal_idx = kTemporalIdx;
485 expected_.temporal_up_switch = kUbit ? true : false;
486 expected_.spatial_idx = kSpatialIdx;
487 expected_.inter_layer_predicted = kDbit ? true : false;
488 ParseAndCheckPacket(packet, expected_, kHeaderLength, sizeof(packet));
489 }
490
491 TEST_F(RtpDepacketizerVp9Test, ParseRefIdx) {
492 const uint8_t kHeaderLength = 7;
493 const int16_t kPictureId = 17;
494 const int16_t kPdiff1 = 17;
495 const int16_t kPdiff2 = 18;
496 const int16_t kExtPdiff3 = 2171;
497 uint8_t packet[13] = {0};
498 packet[0] = 0xD8; // I:1 P:1 L:0 F:1 B:1 E:0 V:0 R:0
499 packet[1] = 0x80 | ((kPictureId >> 8) & 0x7F); // Two byte pictureID.
500 packet[2] = kPictureId;
501 packet[3] = (kPdiff1 << 2) | (0 << 1) | 1; // P_DIFF X:0 N:1
502 packet[4] = (kPdiff2 << 2) | (0 << 1) | 1; // P_DIFF X:0 N:1
503 packet[5] = ((kExtPdiff3 >> 8) << 2) | (1 << 1) | 0; // P_DIFF X:1 N:0
504 packet[6] = kExtPdiff3 & 0xff; // EXTENDED P_DIFF
505
506 // I:1 P:1 L:0 F:1 B:1 E:0 V:0
507 // I: PICTURE ID:17
508 // I:
509 // P,F: P_DIFF:17 X:0 N:1 => refPictureId = 17 - 17 = 0
510 // P,F: P_DIFF:18 X:0 N:1 => refPictureId = 0x7FFF + 1 + 17 - 18 = 0x7FFF
511 // P,F: P_DIFF:2171 X:1 N:0 => refPictureId = 0x7FFF + 1 + 17 - 2171 = 30614
512 expected_.beginning_of_frame = true;
513 expected_.inter_pic_predicted = true;
514 expected_.flexible_mode = true;
515 expected_.picture_id = kPictureId;
516 expected_.num_ref_pics = 3;
517 expected_.pid_diff[0] = kPdiff1;
518 expected_.pid_diff[1] = kPdiff2;
519 expected_.pid_diff[2] = kExtPdiff3;
520 expected_.ref_picture_id[0] = 0;
521 expected_.ref_picture_id[1] = 0x7FFF;
522 expected_.ref_picture_id[2] = 30614;
523 ParseAndCheckPacket(packet, expected_, kHeaderLength, sizeof(packet));
524 }
525
526 TEST_F(RtpDepacketizerVp9Test, ParseRefIdxFailsWithNoPictureId) {
527 const int16_t kPdiff = 3;
528 uint8_t packet[13] = {0};
529 packet[0] = 0x58; // I:0 P:1 L:0 F:1 B:1 E:0 V:0 R:0
530 packet[1] = (kPdiff << 2) | (0 << 1) | 0; // P,F: P_DIFF:3 X:0 N:0
531
532 RtpDepacketizer::ParsedPayload parsed;
533 EXPECT_FALSE(depacketizer_->Parse(&parsed, packet, sizeof(packet)));
534 }
535
536 TEST_F(RtpDepacketizerVp9Test, ParseRefIdxFailsWithTooManyRefPics) {
537 const int16_t kPdiff = 3;
538 uint8_t packet[13] = {0};
539 packet[0] = 0xD8; // I:1 P:1 L:0 F:1 B:1 E:0 V:0 R:0
540 packet[1] = kMaxOneBytePictureId; // I: PICTURE ID:127
541 packet[2] = (kPdiff << 2) | (0 << 1) | 1; // P,F: P_DIFF:3 X:0 N:1
542 packet[3] = (kPdiff << 2) | (0 << 1) | 1; // P,F: P_DIFF:3 X:0 N:1
543 packet[4] = (kPdiff << 2) | (0 << 1) | 1; // P,F: P_DIFF:3 X:0 N:1
544 packet[5] = (kPdiff << 2) | (0 << 1) | 0; // P,F: P_DIFF:3 X:0 N:0
545
546 RtpDepacketizer::ParsedPayload parsed;
547 EXPECT_FALSE(depacketizer_->Parse(&parsed, packet, sizeof(packet)));
548 }
549
550 TEST_F(RtpDepacketizerVp9Test, ParseSsData) {
551 const uint8_t kHeaderLength = 5;
552 const uint8_t kYbit = 0;
553 const size_t kNs = 2;
554 const size_t kNg = 2;
555 uint8_t packet[23] = {0};
556 packet[0] = 0x0A; // I:0 P:0 L:0 F:0 B:1 E:0 V:1 R:0
557 packet[1] = ((kNs - 1) << 5) | (kYbit << 4) | (kNg - 1); // N_S Y N_G
558 packet[2] = (0 << 5) | (1 << 4) | (0 << 2) | 0; // T:0 U:1 R:0 -
559 packet[3] = (2 << 5) | (0 << 4) | (1 << 2) | 0; // T:2 U:0 R:1 -
560 packet[4] = 33;
561
562 expected_.beginning_of_frame = true;
563 expected_.ss_data_available = true;
564 expected_.num_spatial_layers = kNs;
565 expected_.spatial_layer_resolution_present = kYbit ? true : false;
566 expected_.gof.num_frames_in_gof = kNg;
567 expected_.gof.temporal_idx[0] = 0;
568 expected_.gof.temporal_idx[1] = 2;
569 expected_.gof.temporal_up_switch[0] = true;
570 expected_.gof.temporal_up_switch[1] = false;
571 expected_.gof.num_ref_pics[0] = 0;
572 expected_.gof.num_ref_pics[1] = 1;
573 expected_.gof.pid_diff[1][0] = 33;
574 ParseAndCheckPacket(packet, expected_, kHeaderLength, sizeof(packet));
575 }
576
577 TEST_F(RtpDepacketizerVp9Test, ParseFirstPacketInKeyFrame) {
578 uint8_t packet[2] = {0};
579 packet[0] = 0x08; // I:0 P:0 L:0 F:0 B:1 E:0 V:0 R:0
580
581 RtpDepacketizer::ParsedPayload parsed;
582 ASSERT_TRUE(depacketizer_->Parse(&parsed, packet, sizeof(packet)));
583 EXPECT_EQ(kVideoFrameKey, parsed.frame_type);
584 EXPECT_TRUE(parsed.type.Video.isFirstPacket);
585 }
586
587 TEST_F(RtpDepacketizerVp9Test, ParseLastPacketInDeltaFrame) {
588 uint8_t packet[2] = {0};
589 packet[0] = 0x44; // I:0 P:1 L:0 F:0 B:0 E:1 V:0 R:0
590
591 RtpDepacketizer::ParsedPayload parsed;
592 ASSERT_TRUE(depacketizer_->Parse(&parsed, packet, sizeof(packet)));
593 EXPECT_EQ(kVideoFrameDelta, parsed.frame_type);
594 EXPECT_FALSE(parsed.type.Video.isFirstPacket);
595 }
596
597 TEST_F(RtpDepacketizerVp9Test, ParseResolution) {
598 const uint16_t kWidth[2] = {640, 1280};
599 const uint16_t kHeight[2] = {360, 720};
600 uint8_t packet[20] = {0};
601 packet[0] = 0x0A; // I:0 P:0 L:0 F:0 B:1 E:0 V:1 R:0
602 packet[1] = (1 << 5) | (1 << 4) | 0; // N_S:1 Y:1 N_G:0
603 packet[2] = kWidth[0] >> 8;
604 packet[3] = kWidth[0] & 0xFF;
605 packet[4] = kHeight[0] >> 8;
606 packet[5] = kHeight[0] & 0xFF;
607 packet[6] = kWidth[1] >> 8;
608 packet[7] = kWidth[1] & 0xFF;
609 packet[8] = kHeight[1] >> 8;
610 packet[9] = kHeight[1] & 0xFF;
611 packet[10] = 0; // T:0 U:0 R:0 -
612
613 RtpDepacketizer::ParsedPayload parsed;
614 ASSERT_TRUE(depacketizer_->Parse(&parsed, packet, sizeof(packet)));
615 EXPECT_EQ(kWidth[0], parsed.type.Video.width);
616 EXPECT_EQ(kHeight[0], parsed.type.Video.height);
617 }
618
619 TEST_F(RtpDepacketizerVp9Test, ParseFailsForNoPayloadLength) {
620 uint8_t packet[1] = {0};
621 RtpDepacketizer::ParsedPayload parsed;
622 EXPECT_FALSE(depacketizer_->Parse(&parsed, packet, 0));
623 }
624
625 TEST_F(RtpDepacketizerVp9Test, ParseFailsForTooShortBufferToFitPayload) {
626 const uint8_t kHeaderLength = 1;
627 uint8_t packet[kHeaderLength] = {0};
628 RtpDepacketizer::ParsedPayload parsed;
629 EXPECT_FALSE(depacketizer_->Parse(&parsed, packet, sizeof(packet)));
630 }
631
632 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698