OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/logging.h" | 5 #include "base/logging.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
8 | 8 |
9 #include "media/base/decrypt_config.h" | 9 #include "media/base/decrypt_config.h" |
10 #include "media/filters/h264_parser.h" | 10 #include "media/filters/h264_parser.h" |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 *start_code_size = 0; | 206 *start_code_size = 0; |
207 return false; | 207 return false; |
208 } | 208 } |
209 | 209 |
210 bool H264Parser::LocateNALU(off_t* nalu_size, off_t* start_code_size) { | 210 bool H264Parser::LocateNALU(off_t* nalu_size, off_t* start_code_size) { |
211 // Find the start code of next NALU. | 211 // Find the start code of next NALU. |
212 off_t nalu_start_off = 0; | 212 off_t nalu_start_off = 0; |
213 off_t annexb_start_code_size = 0; | 213 off_t annexb_start_code_size = 0; |
214 | 214 |
215 if (!FindStartCodeInClearRanges(stream_, bytes_left_, | 215 if (!FindStartCodeInClearRanges(stream_, bytes_left_, |
| 216 encrypted_ranges_, |
216 &nalu_start_off, &annexb_start_code_size)) { | 217 &nalu_start_off, &annexb_start_code_size)) { |
217 DVLOG(4) << "Could not find start code, end of stream?"; | 218 DVLOG(4) << "Could not find start code, end of stream?"; |
218 return false; | 219 return false; |
219 } | 220 } |
220 | 221 |
221 // Move the stream to the beginning of the NALU (pointing at the start code). | 222 // Move the stream to the beginning of the NALU (pointing at the start code). |
222 stream_ += nalu_start_off; | 223 stream_ += nalu_start_off; |
223 bytes_left_ -= nalu_start_off; | 224 bytes_left_ -= nalu_start_off; |
224 | 225 |
225 const uint8* nalu_data = stream_ + annexb_start_code_size; | 226 const uint8* nalu_data = stream_ + annexb_start_code_size; |
226 off_t max_nalu_data_size = bytes_left_ - annexb_start_code_size; | 227 off_t max_nalu_data_size = bytes_left_ - annexb_start_code_size; |
227 if (max_nalu_data_size <= 0) { | 228 if (max_nalu_data_size <= 0) { |
228 DVLOG(3) << "End of stream"; | 229 DVLOG(3) << "End of stream"; |
229 return false; | 230 return false; |
230 } | 231 } |
231 | 232 |
232 // Find the start code of next NALU; | 233 // Find the start code of next NALU; |
233 // if successful, |nalu_size_without_start_code| is the number of bytes from | 234 // if successful, |nalu_size_without_start_code| is the number of bytes from |
234 // after previous start code to before this one; | 235 // after previous start code to before this one; |
235 // if next start code is not found, it is still a valid NALU since there | 236 // if next start code is not found, it is still a valid NALU since there |
236 // are some bytes left after the first start code: all the remaining bytes | 237 // are some bytes left after the first start code: all the remaining bytes |
237 // belong to the current NALU. | 238 // belong to the current NALU. |
238 off_t next_start_code_size = 0; | 239 off_t next_start_code_size = 0; |
239 off_t nalu_size_without_start_code = 0; | 240 off_t nalu_size_without_start_code = 0; |
240 if (!FindStartCodeInClearRanges(nalu_data, max_nalu_data_size, | 241 if (!FindStartCodeInClearRanges(nalu_data, max_nalu_data_size, |
| 242 encrypted_ranges_, |
241 &nalu_size_without_start_code, | 243 &nalu_size_without_start_code, |
242 &next_start_code_size)) { | 244 &next_start_code_size)) { |
243 nalu_size_without_start_code = max_nalu_data_size; | 245 nalu_size_without_start_code = max_nalu_data_size; |
244 } | 246 } |
245 *nalu_size = nalu_size_without_start_code + annexb_start_code_size; | 247 *nalu_size = nalu_size_without_start_code + annexb_start_code_size; |
246 *start_code_size = annexb_start_code_size; | 248 *start_code_size = annexb_start_code_size; |
247 return true; | 249 return true; |
248 } | 250 } |
249 | 251 |
250 bool H264Parser::FindStartCodeInClearRanges( | 252 bool H264Parser::FindStartCodeInClearRanges( |
251 const uint8* data, | 253 const uint8* data, |
252 off_t data_size, | 254 off_t data_size, |
| 255 const Ranges<const uint8*>& encrypted_ranges, |
253 off_t* offset, | 256 off_t* offset, |
254 off_t* start_code_size) { | 257 off_t* start_code_size) { |
255 if (encrypted_ranges_.size() == 0) | 258 if (encrypted_ranges.size() == 0) |
256 return FindStartCode(data, data_size, offset, start_code_size); | 259 return FindStartCode(data, data_size, offset, start_code_size); |
257 | 260 |
258 DCHECK_GE(data_size, 0); | 261 DCHECK_GE(data_size, 0); |
259 const uint8* start = data; | 262 const uint8* start = data; |
260 do { | 263 do { |
261 off_t bytes_left = data_size - (start - data); | 264 off_t bytes_left = data_size - (start - data); |
262 | 265 |
263 if (!FindStartCode(start, bytes_left, offset, start_code_size)) | 266 if (!FindStartCode(start, bytes_left, offset, start_code_size)) |
264 return false; | 267 return false; |
265 | 268 |
266 // Construct a Ranges object that represents the region occupied | 269 // Construct a Ranges object that represents the region occupied |
267 // by the start code and the 1 byte needed to read the NAL unit type. | 270 // by the start code and the 1 byte needed to read the NAL unit type. |
268 const uint8* start_code = start + *offset; | 271 const uint8* start_code = start + *offset; |
269 const uint8* start_code_end = start_code + *start_code_size; | 272 const uint8* start_code_end = start_code + *start_code_size; |
270 Ranges<const uint8*> start_code_range; | 273 Ranges<const uint8*> start_code_range; |
271 start_code_range.Add(start_code, start_code_end + 1); | 274 start_code_range.Add(start_code, start_code_end + 1); |
272 | 275 |
273 if (encrypted_ranges_.IntersectionWith(start_code_range).size() > 0) { | 276 if (encrypted_ranges.IntersectionWith(start_code_range).size() > 0) { |
274 // The start code is inside an encrypted section so we need to scan | 277 // The start code is inside an encrypted section so we need to scan |
275 // for another start code. | 278 // for another start code. |
276 *start_code_size = 0; | 279 *start_code_size = 0; |
277 start += std::min(*offset + 1, bytes_left); | 280 start += std::min(*offset + 1, bytes_left); |
278 } | 281 } |
279 } while (*start_code_size == 0); | 282 } while (*start_code_size == 0); |
280 | 283 |
281 // Update |*offset| to include the data we skipped over. | 284 // Update |*offset| to include the data we skipped over. |
282 *offset += start - data; | 285 *offset += start - data; |
283 return true; | 286 return true; |
(...skipping 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1316 | 1319 |
1317 default: | 1320 default: |
1318 DVLOG(4) << "Unsupported SEI message"; | 1321 DVLOG(4) << "Unsupported SEI message"; |
1319 break; | 1322 break; |
1320 } | 1323 } |
1321 | 1324 |
1322 return kOk; | 1325 return kOk; |
1323 } | 1326 } |
1324 | 1327 |
1325 } // namespace media | 1328 } // namespace media |
OLD | NEW |