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 // This file contains an implementation of an H264 Annex-B video stream parser. | 5 // This file contains an implementation of an H264 Annex-B video stream parser. |
6 | 6 |
7 #ifndef MEDIA_FILTERS_H264_PARSER_H_ | 7 #ifndef MEDIA_FILTERS_H264_PARSER_H_ |
8 #define MEDIA_FILTERS_H264_PARSER_H_ | 8 #define MEDIA_FILTERS_H264_PARSER_H_ |
9 | 9 |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
11 | 11 |
12 #include <map> | 12 #include <map> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/basictypes.h" | |
16 #include "media/base/media_export.h" | 15 #include "media/base/media_export.h" |
17 #include "media/base/ranges.h" | 16 #include "media/base/ranges.h" |
18 #include "media/filters/h264_bit_reader.h" | 17 #include "media/filters/h264_bit_reader.h" |
19 | 18 |
20 namespace media { | 19 namespace media { |
21 | 20 |
22 struct SubsampleEntry; | 21 struct SubsampleEntry; |
23 | 22 |
24 // For explanations of each struct and its members, see H.264 specification | 23 // For explanations of each struct and its members, see H.264 specification |
25 // at http://www.itu.int/rec/T-REC-H.264. | 24 // at http://www.itu.int/rec/T-REC-H.264. |
(...skipping 19 matching lines...) Expand all Loading... |
45 kReserved15 = 15, | 44 kReserved15 = 15, |
46 kReserved16 = 16, | 45 kReserved16 = 16, |
47 kReserved17 = 17, | 46 kReserved17 = 17, |
48 kReserved18 = 18, | 47 kReserved18 = 18, |
49 kCodedSliceAux = 19, | 48 kCodedSliceAux = 19, |
50 kCodedSliceExtension = 20, | 49 kCodedSliceExtension = 20, |
51 }; | 50 }; |
52 | 51 |
53 // After (without) start code; we don't own the underlying memory | 52 // After (without) start code; we don't own the underlying memory |
54 // and a shallow copy should be made when copying this struct. | 53 // and a shallow copy should be made when copying this struct. |
55 const uint8* data; | 54 const uint8_t* data; |
56 off_t size; // From after start code to start code of next NALU (or EOS). | 55 off_t size; // From after start code to start code of next NALU (or EOS). |
57 | 56 |
58 int nal_ref_idc; | 57 int nal_ref_idc; |
59 int nal_unit_type; | 58 int nal_unit_type; |
60 }; | 59 }; |
61 | 60 |
62 enum { | 61 enum { |
63 kH264ScalingList4x4Length = 16, | 62 kH264ScalingList4x4Length = 16, |
64 kH264ScalingList8x8Length = 64, | 63 kH264ScalingList8x8Length = 64, |
65 }; | 64 }; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 }; | 227 }; |
229 | 228 |
230 bool IsPSlice() const; | 229 bool IsPSlice() const; |
231 bool IsBSlice() const; | 230 bool IsBSlice() const; |
232 bool IsISlice() const; | 231 bool IsISlice() const; |
233 bool IsSPSlice() const; | 232 bool IsSPSlice() const; |
234 bool IsSISlice() const; | 233 bool IsSISlice() const; |
235 | 234 |
236 bool idr_pic_flag; // from NAL header | 235 bool idr_pic_flag; // from NAL header |
237 int nal_ref_idc; // from NAL header | 236 int nal_ref_idc; // from NAL header |
238 const uint8* nalu_data; // from NAL header | 237 const uint8_t* nalu_data; // from NAL header |
239 off_t nalu_size; // from NAL header | 238 off_t nalu_size; // from NAL header |
240 off_t header_bit_size; // calculated | 239 off_t header_bit_size; // calculated |
241 | 240 |
242 int first_mb_in_slice; | 241 int first_mb_in_slice; |
243 int slice_type; | 242 int slice_type; |
244 int pic_parameter_set_id; | 243 int pic_parameter_set_id; |
245 int colour_plane_id; // TODO(posciak): use this! http://crbug.com/139878 | 244 int colour_plane_id; // TODO(posciak): use this! http://crbug.com/139878 |
246 int frame_num; | 245 int frame_num; |
247 bool field_pic_flag; | 246 bool field_pic_flag; |
248 bool bottom_field_flag; | 247 bool bottom_field_flag; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 // and size of found start code (3 or 4 bytes). | 330 // and size of found start code (3 or 4 bytes). |
332 // If no start code is found, offset is pointing to the first unprocessed byte | 331 // If no start code is found, offset is pointing to the first unprocessed byte |
333 // (i.e. the first byte that was not considered as a possible start of a start | 332 // (i.e. the first byte that was not considered as a possible start of a start |
334 // code) and |*start_code_size| is set to 0. | 333 // code) and |*start_code_size| is set to 0. |
335 // Preconditions: | 334 // Preconditions: |
336 // - |data_size| >= 0 | 335 // - |data_size| >= 0 |
337 // Postconditions: | 336 // Postconditions: |
338 // - |*offset| is between 0 and |data_size| included. | 337 // - |*offset| is between 0 and |data_size| included. |
339 // It is strictly less than |data_size| if |data_size| > 0. | 338 // It is strictly less than |data_size| if |data_size| > 0. |
340 // - |*start_code_size| is either 0, 3 or 4. | 339 // - |*start_code_size| is either 0, 3 or 4. |
341 static bool FindStartCode(const uint8* data, off_t data_size, | 340 static bool FindStartCode(const uint8_t* data, |
342 off_t* offset, off_t* start_code_size); | 341 off_t data_size, |
| 342 off_t* offset, |
| 343 off_t* start_code_size); |
343 | 344 |
344 // Wrapper for FindStartCode() that skips over start codes that | 345 // Wrapper for FindStartCode() that skips over start codes that |
345 // may appear inside of |encrypted_ranges_|. | 346 // may appear inside of |encrypted_ranges_|. |
346 // Returns true if a start code was found. Otherwise returns false. | 347 // Returns true if a start code was found. Otherwise returns false. |
347 static bool FindStartCodeInClearRanges(const uint8* data, off_t data_size, | 348 static bool FindStartCodeInClearRanges(const uint8_t* data, |
348 const Ranges<const uint8*>& ranges, | 349 off_t data_size, |
349 off_t* offset, off_t* start_code_size); | 350 const Ranges<const uint8_t*>& ranges, |
| 351 off_t* offset, |
| 352 off_t* start_code_size); |
350 H264Parser(); | 353 H264Parser(); |
351 ~H264Parser(); | 354 ~H264Parser(); |
352 | 355 |
353 void Reset(); | 356 void Reset(); |
354 // Set current stream pointer to |stream| of |stream_size| in bytes, | 357 // Set current stream pointer to |stream| of |stream_size| in bytes, |
355 // |stream| owned by caller. | 358 // |stream| owned by caller. |
356 // |subsamples| contains information about what parts of |stream| are | 359 // |subsamples| contains information about what parts of |stream| are |
357 // encrypted. | 360 // encrypted. |
358 void SetStream(const uint8* stream, off_t stream_size); | 361 void SetStream(const uint8_t* stream, off_t stream_size); |
359 void SetEncryptedStream(const uint8* stream, off_t stream_size, | 362 void SetEncryptedStream(const uint8_t* stream, |
| 363 off_t stream_size, |
360 const std::vector<SubsampleEntry>& subsamples); | 364 const std::vector<SubsampleEntry>& subsamples); |
361 | 365 |
362 // Read the stream to find the next NALU, identify it and return | 366 // Read the stream to find the next NALU, identify it and return |
363 // that information in |*nalu|. This advances the stream to the beginning | 367 // that information in |*nalu|. This advances the stream to the beginning |
364 // of this NALU, but not past it, so subsequent calls to NALU-specific | 368 // of this NALU, but not past it, so subsequent calls to NALU-specific |
365 // parsing functions (ParseSPS, etc.) will parse this NALU. | 369 // parsing functions (ParseSPS, etc.) will parse this NALU. |
366 // If the caller wishes to skip the current NALU, it can call this function | 370 // If the caller wishes to skip the current NALU, it can call this function |
367 // again, instead of any NALU-type specific parse functions below. | 371 // again, instead of any NALU-type specific parse functions below. |
368 Result AdvanceToNextNALU(H264NALU* nalu); | 372 Result AdvanceToNextNALU(H264NALU* nalu); |
369 | 373 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 Result ParseWeightingFactors(int num_ref_idx_active_minus1, | 445 Result ParseWeightingFactors(int num_ref_idx_active_minus1, |
442 int chroma_array_type, | 446 int chroma_array_type, |
443 int luma_log2_weight_denom, | 447 int luma_log2_weight_denom, |
444 int chroma_log2_weight_denom, | 448 int chroma_log2_weight_denom, |
445 H264WeightingFactors* w_facts); | 449 H264WeightingFactors* w_facts); |
446 | 450 |
447 // Parse decoded reference picture marking information (see spec). | 451 // Parse decoded reference picture marking information (see spec). |
448 Result ParseDecRefPicMarking(H264SliceHeader* shdr); | 452 Result ParseDecRefPicMarking(H264SliceHeader* shdr); |
449 | 453 |
450 // Pointer to the current NALU in the stream. | 454 // Pointer to the current NALU in the stream. |
451 const uint8* stream_; | 455 const uint8_t* stream_; |
452 | 456 |
453 // Bytes left in the stream after the current NALU. | 457 // Bytes left in the stream after the current NALU. |
454 off_t bytes_left_; | 458 off_t bytes_left_; |
455 | 459 |
456 H264BitReader br_; | 460 H264BitReader br_; |
457 | 461 |
458 // PPSes and SPSes stored for future reference. | 462 // PPSes and SPSes stored for future reference. |
459 typedef std::map<int, H264SPS*> SPSById; | 463 typedef std::map<int, H264SPS*> SPSById; |
460 typedef std::map<int, H264PPS*> PPSById; | 464 typedef std::map<int, H264PPS*> PPSById; |
461 SPSById active_SPSes_; | 465 SPSById active_SPSes_; |
462 PPSById active_PPSes_; | 466 PPSById active_PPSes_; |
463 | 467 |
464 // Ranges of encrypted bytes in the buffer passed to | 468 // Ranges of encrypted bytes in the buffer passed to |
465 // SetEncryptedStream(). | 469 // SetEncryptedStream(). |
466 Ranges<const uint8*> encrypted_ranges_; | 470 Ranges<const uint8_t*> encrypted_ranges_; |
467 | 471 |
468 DISALLOW_COPY_AND_ASSIGN(H264Parser); | 472 DISALLOW_COPY_AND_ASSIGN(H264Parser); |
469 }; | 473 }; |
470 | 474 |
471 } // namespace media | 475 } // namespace media |
472 | 476 |
473 #endif // MEDIA_FILTERS_H264_PARSER_H_ | 477 #endif // MEDIA_FILTERS_H264_PARSER_H_ |
OLD | NEW |