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

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

Issue 1362503003: Use suffixed {uint,int}{8,16,32,64}_t types. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase + revert basictypes.h (to be landed separately just in case of a revert due to unexpected us… Created 5 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) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 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 20 matching lines...) Expand all
31 // two start codes (0 0 0 1 or 0 0 1). The first byte should be 0x67, 31 // two start codes (0 0 0 1 or 0 0 1). The first byte should be 0x67,
32 // which should be stripped out before being passed to the parser. 32 // which should be stripped out before being passed to the parser.
33 33
34 static const size_t kSpsBufferMaxSize = 256; 34 static const size_t kSpsBufferMaxSize = 256;
35 35
36 // Generates a fake SPS with basically everything empty but the width/height. 36 // Generates a fake SPS with basically everything empty but the width/height.
37 // Pass in a buffer of at least kSpsBufferMaxSize. 37 // Pass in a buffer of at least kSpsBufferMaxSize.
38 // The fake SPS that this generates also always has at least one emulation byte 38 // The fake SPS that this generates also always has at least one emulation byte
39 // at offset 2, since the first two bytes are always 0, and has a 0x3 as the 39 // at offset 2, since the first two bytes are always 0, and has a 0x3 as the
40 // level_idc, to make sure the parser doesn't eat all 0x3 bytes. 40 // level_idc, to make sure the parser doesn't eat all 0x3 bytes.
41 void GenerateFakeSps(uint16 width, uint16 height, uint8 buffer[]) { 41 void GenerateFakeSps(uint16_t width, uint16_t height, uint8_t buffer[]) {
42 uint8 rbsp[kSpsBufferMaxSize] = {0}; 42 uint8_t rbsp[kSpsBufferMaxSize] = {0};
43 rtc::BitBufferWriter writer(rbsp, kSpsBufferMaxSize); 43 rtc::BitBufferWriter writer(rbsp, kSpsBufferMaxSize);
44 // Profile byte. 44 // Profile byte.
45 writer.WriteUInt8(0); 45 writer.WriteUInt8(0);
46 // Constraint sets and reserved zero bits. 46 // Constraint sets and reserved zero bits.
47 writer.WriteUInt8(0); 47 writer.WriteUInt8(0);
48 // level_idc. 48 // level_idc.
49 writer.WriteUInt8(0x3u); 49 writer.WriteUInt8(0x3u);
50 // seq_paramter_set_id. 50 // seq_paramter_set_id.
51 writer.WriteExponentialGolomb(0); 51 writer.WriteExponentialGolomb(0);
52 // Profile is not special, so we skip all the chroma format settings. 52 // Profile is not special, so we skip all the chroma format settings.
53 53
54 // Now some bit magic. 54 // Now some bit magic.
55 // log2_max_frame_num_minus4: ue(v). 0 is fine. 55 // log2_max_frame_num_minus4: ue(v). 0 is fine.
56 writer.WriteExponentialGolomb(0); 56 writer.WriteExponentialGolomb(0);
57 // pic_order_cnt_type: ue(v). 0 is the type we want. 57 // pic_order_cnt_type: ue(v). 0 is the type we want.
58 writer.WriteExponentialGolomb(0); 58 writer.WriteExponentialGolomb(0);
59 // log2_max_pic_order_cnt_lsb_minus4: ue(v). 0 is fine. 59 // log2_max_pic_order_cnt_lsb_minus4: ue(v). 0 is fine.
60 writer.WriteExponentialGolomb(0); 60 writer.WriteExponentialGolomb(0);
61 // max_num_ref_frames: ue(v). 0 is fine. 61 // max_num_ref_frames: ue(v). 0 is fine.
62 writer.WriteExponentialGolomb(0); 62 writer.WriteExponentialGolomb(0);
63 // gaps_in_frame_num_value_allowed_flag: u(1). 63 // gaps_in_frame_num_value_allowed_flag: u(1).
64 writer.WriteBits(0, 1); 64 writer.WriteBits(0, 1);
65 // Next are width/height. First, calculate the mbs/map_units versions. 65 // Next are width/height. First, calculate the mbs/map_units versions.
66 uint16 width_in_mbs_minus1 = (width + 15) / 16 - 1; 66 uint16_t width_in_mbs_minus1 = (width + 15) / 16 - 1;
67 67
68 // For the height, we're going to define frame_mbs_only_flag, so we need to 68 // For the height, we're going to define frame_mbs_only_flag, so we need to
69 // divide by 2. See the parser for the full calculation. 69 // divide by 2. See the parser for the full calculation.
70 uint16 height_in_map_units_minus1 = ((height + 15) / 16 - 1) / 2; 70 uint16_t height_in_map_units_minus1 = ((height + 15) / 16 - 1) / 2;
71 // Write each as ue(v). 71 // Write each as ue(v).
72 writer.WriteExponentialGolomb(width_in_mbs_minus1); 72 writer.WriteExponentialGolomb(width_in_mbs_minus1);
73 writer.WriteExponentialGolomb(height_in_map_units_minus1); 73 writer.WriteExponentialGolomb(height_in_map_units_minus1);
74 // frame_mbs_only_flag: u(1). Needs to be false. 74 // frame_mbs_only_flag: u(1). Needs to be false.
75 writer.WriteBits(0, 1); 75 writer.WriteBits(0, 1);
76 // mb_adaptive_frame_field_flag: u(1). 76 // mb_adaptive_frame_field_flag: u(1).
77 writer.WriteBits(0, 1); 77 writer.WriteBits(0, 1);
78 // direct_8x8_inferene_flag: u(1). 78 // direct_8x8_inferene_flag: u(1).
79 writer.WriteBits(0, 1); 79 writer.WriteBits(0, 1);
80 // frame_cropping_flag: u(1). 1, so we can supply crop. 80 // frame_cropping_flag: u(1). 1, so we can supply crop.
(...skipping 30 matching lines...) Expand all
111 } else { 111 } else {
112 *buffer++ = rbsp[i]; 112 *buffer++ = rbsp[i];
113 ++i; 113 ++i;
114 } 114 }
115 } 115 }
116 } 116 }
117 117
118 TEST(H264SpsParserTest, TestSampleSPSHdLandscape) { 118 TEST(H264SpsParserTest, TestSampleSPSHdLandscape) {
119 // SPS for a 1280x720 camera capture from ffmpeg on osx. Contains 119 // SPS for a 1280x720 camera capture from ffmpeg on osx. Contains
120 // emulation bytes but no cropping. 120 // emulation bytes but no cropping.
121 const uint8 buffer[] = {0x7A, 0x00, 0x1F, 0xBC, 0xD9, 0x40, 0x50, 0x05, 121 const uint8_t buffer[] = {0x7A, 0x00, 0x1F, 0xBC, 0xD9, 0x40, 0x50, 0x05,
122 0xBA, 0x10, 0x00, 0x00, 0x03, 0x00, 0xC0, 0x00, 122 0xBA, 0x10, 0x00, 0x00, 0x03, 0x00, 0xC0, 0x00,
123 0x00, 0x2A, 0xE0, 0xF1, 0x83, 0x19, 0x60}; 123 0x00, 0x2A, 0xE0, 0xF1, 0x83, 0x19, 0x60};
124 H264SpsParser parser = H264SpsParser(buffer, ARRAY_SIZE(buffer)); 124 H264SpsParser parser = H264SpsParser(buffer, ARRAY_SIZE(buffer));
125 EXPECT_TRUE(parser.Parse()); 125 EXPECT_TRUE(parser.Parse());
126 EXPECT_EQ(1280u, parser.width()); 126 EXPECT_EQ(1280u, parser.width());
127 EXPECT_EQ(720u, parser.height()); 127 EXPECT_EQ(720u, parser.height());
128 } 128 }
129 129
130 TEST(H264SpsParserTest, TestSampleSPSVgaLandscape) { 130 TEST(H264SpsParserTest, TestSampleSPSVgaLandscape) {
131 // SPS for a 640x360 camera capture from ffmpeg on osx. Contains emulation 131 // SPS for a 640x360 camera capture from ffmpeg on osx. Contains emulation
132 // bytes and cropping (360 isn't divisible by 16). 132 // bytes and cropping (360 isn't divisible by 16).
133 const uint8 buffer[] = {0x7A, 0x00, 0x1E, 0xBC, 0xD9, 0x40, 0xA0, 0x2F, 133 const uint8_t buffer[] = {0x7A, 0x00, 0x1E, 0xBC, 0xD9, 0x40, 0xA0, 0x2F,
134 0xF8, 0x98, 0x40, 0x00, 0x00, 0x03, 0x01, 0x80, 134 0xF8, 0x98, 0x40, 0x00, 0x00, 0x03, 0x01, 0x80,
135 0x00, 0x00, 0x56, 0x83, 0xC5, 0x8B, 0x65, 0x80}; 135 0x00, 0x00, 0x56, 0x83, 0xC5, 0x8B, 0x65, 0x80};
136 H264SpsParser parser = H264SpsParser(buffer, ARRAY_SIZE(buffer)); 136 H264SpsParser parser = H264SpsParser(buffer, ARRAY_SIZE(buffer));
137 EXPECT_TRUE(parser.Parse()); 137 EXPECT_TRUE(parser.Parse());
138 EXPECT_EQ(640u, parser.width()); 138 EXPECT_EQ(640u, parser.width());
139 EXPECT_EQ(360u, parser.height()); 139 EXPECT_EQ(360u, parser.height());
140 } 140 }
141 141
142 TEST(H264SpsParserTest, TestSampleSPSWeirdResolution) { 142 TEST(H264SpsParserTest, TestSampleSPSWeirdResolution) {
143 // SPS for a 200x400 camera capture from ffmpeg on osx. Horizontal and 143 // SPS for a 200x400 camera capture from ffmpeg on osx. Horizontal and
144 // veritcal crop (neither dimension is divisible by 16). 144 // veritcal crop (neither dimension is divisible by 16).
145 const uint8 buffer[] = {0x7A, 0x00, 0x0D, 0xBC, 0xD9, 0x43, 0x43, 0x3E, 145 const uint8_t buffer[] = {0x7A, 0x00, 0x0D, 0xBC, 0xD9, 0x43, 0x43, 0x3E,
146 0x5E, 0x10, 0x00, 0x00, 0x03, 0x00, 0x60, 0x00, 146 0x5E, 0x10, 0x00, 0x00, 0x03, 0x00, 0x60, 0x00,
147 0x00, 0x15, 0xA0, 0xF1, 0x42, 0x99, 0x60}; 147 0x00, 0x15, 0xA0, 0xF1, 0x42, 0x99, 0x60};
148 H264SpsParser parser = H264SpsParser(buffer, ARRAY_SIZE(buffer)); 148 H264SpsParser parser = H264SpsParser(buffer, ARRAY_SIZE(buffer));
149 EXPECT_TRUE(parser.Parse()); 149 EXPECT_TRUE(parser.Parse());
150 EXPECT_EQ(200u, parser.width()); 150 EXPECT_EQ(200u, parser.width());
151 EXPECT_EQ(400u, parser.height()); 151 EXPECT_EQ(400u, parser.height());
152 } 152 }
153 153
154 TEST(H264SpsParserTest, TestSyntheticSPSQvgaLandscape) { 154 TEST(H264SpsParserTest, TestSyntheticSPSQvgaLandscape) {
155 uint8 buffer[kSpsBufferMaxSize] = {0}; 155 uint8_t buffer[kSpsBufferMaxSize] = {0};
156 GenerateFakeSps(320u, 180u, buffer); 156 GenerateFakeSps(320u, 180u, buffer);
157 H264SpsParser parser = H264SpsParser(buffer, ARRAY_SIZE(buffer)); 157 H264SpsParser parser = H264SpsParser(buffer, ARRAY_SIZE(buffer));
158 EXPECT_TRUE(parser.Parse()); 158 EXPECT_TRUE(parser.Parse());
159 EXPECT_EQ(320u, parser.width()); 159 EXPECT_EQ(320u, parser.width());
160 EXPECT_EQ(180u, parser.height()); 160 EXPECT_EQ(180u, parser.height());
161 } 161 }
162 162
163 TEST(H264SpsParserTest, TestSyntheticSPSWeirdResolution) { 163 TEST(H264SpsParserTest, TestSyntheticSPSWeirdResolution) {
164 uint8 buffer[kSpsBufferMaxSize] = {0}; 164 uint8_t buffer[kSpsBufferMaxSize] = {0};
165 GenerateFakeSps(156u, 122u, buffer); 165 GenerateFakeSps(156u, 122u, buffer);
166 H264SpsParser parser = H264SpsParser(buffer, ARRAY_SIZE(buffer)); 166 H264SpsParser parser = H264SpsParser(buffer, ARRAY_SIZE(buffer));
167 EXPECT_TRUE(parser.Parse()); 167 EXPECT_TRUE(parser.Parse());
168 EXPECT_EQ(156u, parser.width()); 168 EXPECT_EQ(156u, parser.width());
169 EXPECT_EQ(122u, parser.height()); 169 EXPECT_EQ(122u, parser.height());
170 } 170 }
171 171
172 } // namespace webrtc 172 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698