OLD | NEW |
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 11 matching lines...) Expand all Loading... |
22 namespace { | 22 namespace { |
23 const uint8_t start_code[] = {0, 0, 0, 1}; | 23 const uint8_t start_code[] = {0, 0, 0, 1}; |
24 } // namespace | 24 } // namespace |
25 | 25 |
26 class TestH264SpsPpsTracker : public ::testing::Test { | 26 class TestH264SpsPpsTracker : public ::testing::Test { |
27 public: | 27 public: |
28 VCMPacket GetDefaultPacket() { | 28 VCMPacket GetDefaultPacket() { |
29 VCMPacket packet; | 29 VCMPacket packet; |
30 packet.codec = kVideoCodecH264; | 30 packet.codec = kVideoCodecH264; |
31 packet.video_header.codecHeader.H264.nalus_length = 0; | 31 packet.video_header.codecHeader.H264.nalus_length = 0; |
32 packet.video_header.isFirstPacket = false; | 32 packet.video_header.is_first_packet_in_frame = false; |
33 packet.video_header.codecHeader.H264.packetization_type = kH264SingleNalu; | 33 packet.video_header.codecHeader.H264.packetization_type = kH264SingleNalu; |
34 | 34 |
35 return packet; | 35 return packet; |
36 } | 36 } |
37 | 37 |
38 void AddSps(VCMPacket* packet, int sps_id, std::vector<uint8_t>* data) { | 38 void AddSps(VCMPacket* packet, int sps_id, std::vector<uint8_t>* data) { |
39 NaluInfo info; | 39 NaluInfo info; |
40 info.type = H264::NaluType::kSps; | 40 info.type = H264::NaluType::kSps; |
41 info.sps_id = sps_id; | 41 info.sps_id = sps_id; |
42 info.pps_id = -1; | 42 info.pps_id = -1; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 89 |
90 EXPECT_EQ(H264SpsPpsTracker::kInsert, tracker_.CopyAndFixBitstream(&packet)); | 90 EXPECT_EQ(H264SpsPpsTracker::kInsert, tracker_.CopyAndFixBitstream(&packet)); |
91 EXPECT_EQ(memcmp(packet.dataPtr, data, sizeof(data)), 0); | 91 EXPECT_EQ(memcmp(packet.dataPtr, data, sizeof(data)), 0); |
92 delete[] packet.dataPtr; | 92 delete[] packet.dataPtr; |
93 } | 93 } |
94 | 94 |
95 TEST_F(TestH264SpsPpsTracker, FuAFirstPacket) { | 95 TEST_F(TestH264SpsPpsTracker, FuAFirstPacket) { |
96 uint8_t data[] = {1, 2, 3}; | 96 uint8_t data[] = {1, 2, 3}; |
97 VCMPacket packet = GetDefaultPacket(); | 97 VCMPacket packet = GetDefaultPacket(); |
98 packet.video_header.codecHeader.H264.packetization_type = kH264FuA; | 98 packet.video_header.codecHeader.H264.packetization_type = kH264FuA; |
99 packet.video_header.isFirstPacket = true; | 99 packet.video_header.is_first_packet_in_frame = true; |
100 packet.dataPtr = data; | 100 packet.dataPtr = data; |
101 packet.sizeBytes = sizeof(data); | 101 packet.sizeBytes = sizeof(data); |
102 | 102 |
103 EXPECT_EQ(H264SpsPpsTracker::kInsert, tracker_.CopyAndFixBitstream(&packet)); | 103 EXPECT_EQ(H264SpsPpsTracker::kInsert, tracker_.CopyAndFixBitstream(&packet)); |
104 std::vector<uint8_t> expected; | 104 std::vector<uint8_t> expected; |
105 expected.insert(expected.end(), start_code, start_code + sizeof(start_code)); | 105 expected.insert(expected.end(), start_code, start_code + sizeof(start_code)); |
106 expected.insert(expected.end(), {1, 2, 3}); | 106 expected.insert(expected.end(), {1, 2, 3}); |
107 EXPECT_EQ(memcmp(packet.dataPtr, expected.data(), expected.size()), 0); | 107 EXPECT_EQ(memcmp(packet.dataPtr, expected.data(), expected.size()), 0); |
108 delete[] packet.dataPtr; | 108 delete[] packet.dataPtr; |
109 } | 109 } |
110 | 110 |
111 TEST_F(TestH264SpsPpsTracker, StapAIncorrectSegmentLength) { | 111 TEST_F(TestH264SpsPpsTracker, StapAIncorrectSegmentLength) { |
112 uint8_t data[] = {0, 0, 2, 0}; | 112 uint8_t data[] = {0, 0, 2, 0}; |
113 VCMPacket packet = GetDefaultPacket(); | 113 VCMPacket packet = GetDefaultPacket(); |
114 packet.video_header.codecHeader.H264.packetization_type = kH264StapA; | 114 packet.video_header.codecHeader.H264.packetization_type = kH264StapA; |
115 packet.video_header.isFirstPacket = true; | 115 packet.video_header.is_first_packet_in_frame = true; |
116 packet.dataPtr = data; | 116 packet.dataPtr = data; |
117 packet.sizeBytes = sizeof(data); | 117 packet.sizeBytes = sizeof(data); |
118 | 118 |
119 EXPECT_EQ(H264SpsPpsTracker::kDrop, tracker_.CopyAndFixBitstream(&packet)); | 119 EXPECT_EQ(H264SpsPpsTracker::kDrop, tracker_.CopyAndFixBitstream(&packet)); |
120 } | 120 } |
121 | 121 |
122 TEST_F(TestH264SpsPpsTracker, NoNalusFirstPacket) { | 122 TEST_F(TestH264SpsPpsTracker, NoNalusFirstPacket) { |
123 uint8_t data[] = {1, 2, 3}; | 123 uint8_t data[] = {1, 2, 3}; |
124 VCMPacket packet = GetDefaultPacket(); | 124 VCMPacket packet = GetDefaultPacket(); |
125 packet.video_header.isFirstPacket = true; | 125 packet.video_header.is_first_packet_in_frame = true; |
126 packet.dataPtr = data; | 126 packet.dataPtr = data; |
127 packet.sizeBytes = sizeof(data); | 127 packet.sizeBytes = sizeof(data); |
128 | 128 |
129 EXPECT_EQ(H264SpsPpsTracker::kInsert, tracker_.CopyAndFixBitstream(&packet)); | 129 EXPECT_EQ(H264SpsPpsTracker::kInsert, tracker_.CopyAndFixBitstream(&packet)); |
130 std::vector<uint8_t> expected; | 130 std::vector<uint8_t> expected; |
131 expected.insert(expected.end(), start_code, start_code + sizeof(start_code)); | 131 expected.insert(expected.end(), start_code, start_code + sizeof(start_code)); |
132 expected.insert(expected.end(), {1, 2, 3}); | 132 expected.insert(expected.end(), {1, 2, 3}); |
133 EXPECT_EQ(memcmp(packet.dataPtr, expected.data(), expected.size()), 0); | 133 EXPECT_EQ(memcmp(packet.dataPtr, expected.data(), expected.size()), 0); |
134 delete[] packet.dataPtr; | 134 delete[] packet.dataPtr; |
135 } | 135 } |
136 | 136 |
137 TEST_F(TestH264SpsPpsTracker, IdrNoSpsPpsInserted) { | 137 TEST_F(TestH264SpsPpsTracker, IdrNoSpsPpsInserted) { |
138 std::vector<uint8_t> data = {1, 2, 3}; | 138 std::vector<uint8_t> data = {1, 2, 3}; |
139 VCMPacket packet = GetDefaultPacket(); | 139 VCMPacket packet = GetDefaultPacket(); |
140 packet.video_header.codecHeader.H264.packetization_type = kH264FuA; | 140 packet.video_header.codecHeader.H264.packetization_type = kH264FuA; |
141 | 141 |
142 AddIdr(&packet, 0); | 142 AddIdr(&packet, 0); |
143 packet.dataPtr = data.data(); | 143 packet.dataPtr = data.data(); |
144 packet.sizeBytes = data.size(); | 144 packet.sizeBytes = data.size(); |
145 | 145 |
146 EXPECT_EQ(H264SpsPpsTracker::kInsert, tracker_.CopyAndFixBitstream(&packet)); | 146 EXPECT_EQ(H264SpsPpsTracker::kInsert, tracker_.CopyAndFixBitstream(&packet)); |
147 EXPECT_EQ(memcmp(packet.dataPtr, data.data(), data.size()), 0); | 147 EXPECT_EQ(memcmp(packet.dataPtr, data.data(), data.size()), 0); |
148 delete[] packet.dataPtr; | 148 delete[] packet.dataPtr; |
149 } | 149 } |
150 | 150 |
151 TEST_F(TestH264SpsPpsTracker, IdrFirstPacketNoSpsPpsInserted) { | 151 TEST_F(TestH264SpsPpsTracker, IdrFirstPacketNoSpsPpsInserted) { |
152 std::vector<uint8_t> data = {1, 2, 3}; | 152 std::vector<uint8_t> data = {1, 2, 3}; |
153 VCMPacket packet = GetDefaultPacket(); | 153 VCMPacket packet = GetDefaultPacket(); |
154 packet.video_header.isFirstPacket = true; | 154 packet.video_header.is_first_packet_in_frame = true; |
155 | 155 |
156 AddIdr(&packet, 0); | 156 AddIdr(&packet, 0); |
157 packet.dataPtr = data.data(); | 157 packet.dataPtr = data.data(); |
158 packet.sizeBytes = data.size(); | 158 packet.sizeBytes = data.size(); |
159 | 159 |
160 EXPECT_EQ(H264SpsPpsTracker::kRequestKeyframe, | 160 EXPECT_EQ(H264SpsPpsTracker::kRequestKeyframe, |
161 tracker_.CopyAndFixBitstream(&packet)); | 161 tracker_.CopyAndFixBitstream(&packet)); |
162 } | 162 } |
163 | 163 |
164 TEST_F(TestH264SpsPpsTracker, IdrFirstPacketNoPpsInserted) { | 164 TEST_F(TestH264SpsPpsTracker, IdrFirstPacketNoPpsInserted) { |
165 std::vector<uint8_t> data = {1, 2, 3}; | 165 std::vector<uint8_t> data = {1, 2, 3}; |
166 VCMPacket packet = GetDefaultPacket(); | 166 VCMPacket packet = GetDefaultPacket(); |
167 packet.video_header.isFirstPacket = true; | 167 packet.video_header.is_first_packet_in_frame = true; |
168 | 168 |
169 AddSps(&packet, 0, &data); | 169 AddSps(&packet, 0, &data); |
170 AddIdr(&packet, 0); | 170 AddIdr(&packet, 0); |
171 packet.dataPtr = data.data(); | 171 packet.dataPtr = data.data(); |
172 packet.sizeBytes = data.size(); | 172 packet.sizeBytes = data.size(); |
173 | 173 |
174 EXPECT_EQ(H264SpsPpsTracker::kRequestKeyframe, | 174 EXPECT_EQ(H264SpsPpsTracker::kRequestKeyframe, |
175 tracker_.CopyAndFixBitstream(&packet)); | 175 tracker_.CopyAndFixBitstream(&packet)); |
176 } | 176 } |
177 | 177 |
178 TEST_F(TestH264SpsPpsTracker, IdrFirstPacketNoSpsInserted) { | 178 TEST_F(TestH264SpsPpsTracker, IdrFirstPacketNoSpsInserted) { |
179 std::vector<uint8_t> data = {1, 2, 3}; | 179 std::vector<uint8_t> data = {1, 2, 3}; |
180 VCMPacket packet = GetDefaultPacket(); | 180 VCMPacket packet = GetDefaultPacket(); |
181 packet.video_header.isFirstPacket = true; | 181 packet.video_header.is_first_packet_in_frame = true; |
182 | 182 |
183 AddPps(&packet, 0, 0, &data); | 183 AddPps(&packet, 0, 0, &data); |
184 AddIdr(&packet, 0); | 184 AddIdr(&packet, 0); |
185 packet.dataPtr = data.data(); | 185 packet.dataPtr = data.data(); |
186 packet.sizeBytes = data.size(); | 186 packet.sizeBytes = data.size(); |
187 | 187 |
188 EXPECT_EQ(H264SpsPpsTracker::kRequestKeyframe, | 188 EXPECT_EQ(H264SpsPpsTracker::kRequestKeyframe, |
189 tracker_.CopyAndFixBitstream(&packet)); | 189 tracker_.CopyAndFixBitstream(&packet)); |
190 } | 190 } |
191 | 191 |
192 TEST_F(TestH264SpsPpsTracker, SpsPpsPacketThenIdrFirstPacket) { | 192 TEST_F(TestH264SpsPpsTracker, SpsPpsPacketThenIdrFirstPacket) { |
193 std::vector<uint8_t> data; | 193 std::vector<uint8_t> data; |
194 VCMPacket sps_pps_packet = GetDefaultPacket(); | 194 VCMPacket sps_pps_packet = GetDefaultPacket(); |
195 | 195 |
196 // Insert SPS/PPS | 196 // Insert SPS/PPS |
197 AddSps(&sps_pps_packet, 0, &data); | 197 AddSps(&sps_pps_packet, 0, &data); |
198 AddPps(&sps_pps_packet, 0, 1, &data); | 198 AddPps(&sps_pps_packet, 0, 1, &data); |
199 sps_pps_packet.dataPtr = data.data(); | 199 sps_pps_packet.dataPtr = data.data(); |
200 sps_pps_packet.sizeBytes = data.size(); | 200 sps_pps_packet.sizeBytes = data.size(); |
201 EXPECT_EQ(H264SpsPpsTracker::kDrop, | 201 EXPECT_EQ(H264SpsPpsTracker::kDrop, |
202 tracker_.CopyAndFixBitstream(&sps_pps_packet)); | 202 tracker_.CopyAndFixBitstream(&sps_pps_packet)); |
203 data.clear(); | 203 data.clear(); |
204 | 204 |
205 // Insert first packet of the IDR | 205 // Insert first packet of the IDR |
206 VCMPacket idr_packet = GetDefaultPacket(); | 206 VCMPacket idr_packet = GetDefaultPacket(); |
207 idr_packet.video_header.isFirstPacket = true; | 207 idr_packet.video_header.is_first_packet_in_frame = true; |
208 AddIdr(&idr_packet, 1); | 208 AddIdr(&idr_packet, 1); |
209 data.insert(data.end(), {1, 2, 3}); | 209 data.insert(data.end(), {1, 2, 3}); |
210 idr_packet.dataPtr = data.data(); | 210 idr_packet.dataPtr = data.data(); |
211 idr_packet.sizeBytes = data.size(); | 211 idr_packet.sizeBytes = data.size(); |
212 EXPECT_EQ(H264SpsPpsTracker::kInsert, | 212 EXPECT_EQ(H264SpsPpsTracker::kInsert, |
213 tracker_.CopyAndFixBitstream(&idr_packet)); | 213 tracker_.CopyAndFixBitstream(&idr_packet)); |
214 | 214 |
215 std::vector<uint8_t> expected; | 215 std::vector<uint8_t> expected; |
216 expected.insert(expected.end(), start_code, start_code + sizeof(start_code)); | 216 expected.insert(expected.end(), start_code, start_code + sizeof(start_code)); |
217 expected.insert(expected.end(), {H264::NaluType::kSps, 0}); | 217 expected.insert(expected.end(), {H264::NaluType::kSps, 0}); |
218 expected.insert(expected.end(), start_code, start_code + sizeof(start_code)); | 218 expected.insert(expected.end(), start_code, start_code + sizeof(start_code)); |
219 expected.insert(expected.end(), {H264::NaluType::kPps, 1}); | 219 expected.insert(expected.end(), {H264::NaluType::kPps, 1}); |
220 expected.insert(expected.end(), start_code, start_code + sizeof(start_code)); | 220 expected.insert(expected.end(), start_code, start_code + sizeof(start_code)); |
221 expected.insert(expected.end(), {1, 2, 3}); | 221 expected.insert(expected.end(), {1, 2, 3}); |
222 EXPECT_EQ(memcmp(idr_packet.dataPtr, expected.data(), expected.size()), 0); | 222 EXPECT_EQ(memcmp(idr_packet.dataPtr, expected.data(), expected.size()), 0); |
223 delete[] idr_packet.dataPtr; | 223 delete[] idr_packet.dataPtr; |
224 } | 224 } |
225 | 225 |
226 TEST_F(TestH264SpsPpsTracker, SpsPpsIdrInStapA) { | 226 TEST_F(TestH264SpsPpsTracker, SpsPpsIdrInStapA) { |
227 std::vector<uint8_t> data; | 227 std::vector<uint8_t> data; |
228 VCMPacket packet = GetDefaultPacket(); | 228 VCMPacket packet = GetDefaultPacket(); |
229 packet.video_header.codecHeader.H264.packetization_type = kH264StapA; | 229 packet.video_header.codecHeader.H264.packetization_type = kH264StapA; |
230 packet.video_header.isFirstPacket = true; // Always true for StapA | 230 packet.video_header.is_first_packet_in_frame = true; // Always true for StapA |
231 | 231 |
232 data.insert(data.end(), {0}); // First byte is ignored | 232 data.insert(data.end(), {0}); // First byte is ignored |
233 data.insert(data.end(), {0, 2}); // Length of segment | 233 data.insert(data.end(), {0, 2}); // Length of segment |
234 AddSps(&packet, 13, &data); | 234 AddSps(&packet, 13, &data); |
235 data.insert(data.end(), {0, 2}); // Length of segment | 235 data.insert(data.end(), {0, 2}); // Length of segment |
236 AddPps(&packet, 13, 27, &data); | 236 AddPps(&packet, 13, 27, &data); |
237 data.insert(data.end(), {0, 5}); // Length of segment | 237 data.insert(data.end(), {0, 5}); // Length of segment |
238 AddIdr(&packet, 27); | 238 AddIdr(&packet, 27); |
239 data.insert(data.end(), {1, 2, 3, 2, 1}); | 239 data.insert(data.end(), {1, 2, 3, 2, 1}); |
240 | 240 |
(...skipping 15 matching lines...) Expand all Loading... |
256 expected.insert(expected.end(), {H264::NaluType::kPps, 27}); | 256 expected.insert(expected.end(), {H264::NaluType::kPps, 27}); |
257 expected.insert(expected.end(), start_code, start_code + sizeof(start_code)); | 257 expected.insert(expected.end(), start_code, start_code + sizeof(start_code)); |
258 expected.insert(expected.end(), {1, 2, 3, 2, 1}); | 258 expected.insert(expected.end(), {1, 2, 3, 2, 1}); |
259 | 259 |
260 EXPECT_EQ(memcmp(packet.dataPtr, expected.data(), expected.size()), 0); | 260 EXPECT_EQ(memcmp(packet.dataPtr, expected.data(), expected.size()), 0); |
261 delete[] packet.dataPtr; | 261 delete[] packet.dataPtr; |
262 } | 262 } |
263 | 263 |
264 } // namespace video_coding | 264 } // namespace video_coding |
265 } // namespace webrtc | 265 } // namespace webrtc |
OLD | NEW |