| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CONTENT_COMMON_GPU_MEDIA_H264_PARSER_H_ | 7 #ifndef CONTENT_COMMON_GPU_MEDIA_H264_PARSER_H_ |
| 8 #define CONTENT_COMMON_GPU_MEDIA_H264_PARSER_H_ | 8 #define CONTENT_COMMON_GPU_MEDIA_H264_PARSER_H_ |
| 9 | 9 |
| 10 #include <sys/types.h> | 10 #include <sys/types.h> |
| 11 | 11 |
| 12 #include <map> | 12 #include <map> |
| 13 | 13 |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "content/common/content_export.h" |
| 15 | 16 |
| 16 namespace content { | 17 namespace content { |
| 17 | 18 |
| 18 // For explanations of each struct and its members, see H.264 specification | 19 // For explanations of each struct and its members, see H.264 specification |
| 19 // at http://www.itu.int/rec/T-REC-H.264. | 20 // at http://www.itu.int/rec/T-REC-H.264. |
| 20 struct H264NALU { | 21 struct CONTENT_EXPORT H264NALU { |
| 21 H264NALU(); | 22 H264NALU(); |
| 22 | 23 |
| 23 enum Type { | 24 enum Type { |
| 24 kUnspecified = 0, | 25 kUnspecified = 0, |
| 25 kNonIDRSlice = 1, | 26 kNonIDRSlice = 1, |
| 26 kIDRSlice = 5, | 27 kIDRSlice = 5, |
| 27 kSEIMessage = 6, | 28 kSEIMessage = 6, |
| 28 kSPS = 7, | 29 kSPS = 7, |
| 29 kPPS = 8, | 30 kPPS = 8, |
| 30 kEOSeq = 9, | 31 kEOSeq = 9, |
| 31 kEOStream = 11, | 32 kEOStream = 11, |
| 32 kCodedSliceExtension = 20, | 33 kCodedSliceExtension = 20, |
| 33 }; | 34 }; |
| 34 | 35 |
| 35 // After (without) start code; we don't own the underlying memory | 36 // After (without) start code; we don't own the underlying memory |
| 36 // and a shallow copy should be made when copying this struct. | 37 // and a shallow copy should be made when copying this struct. |
| 37 const uint8* data; | 38 const uint8* data; |
| 38 off_t size; // From after start code to start code of next NALU (or EOS). | 39 off_t size; // From after start code to start code of next NALU (or EOS). |
| 39 | 40 |
| 40 int nal_ref_idc; | 41 int nal_ref_idc; |
| 41 int nal_unit_type; | 42 int nal_unit_type; |
| 42 }; | 43 }; |
| 43 | 44 |
| 44 enum { kH264ScalingList4x4Length = 16, kH264ScalingList8x8Length = 64, }; | 45 enum { kH264ScalingList4x4Length = 16, kH264ScalingList8x8Length = 64, }; |
| 45 | 46 |
| 46 struct H264SPS { | 47 struct CONTENT_EXPORT H264SPS { |
| 47 H264SPS(); | 48 H264SPS(); |
| 48 | 49 |
| 49 int profile_idc; | 50 int profile_idc; |
| 51 int constraint_setx_flag; |
| 50 int level_idc; | 52 int level_idc; |
| 51 int seq_parameter_set_id; | 53 int seq_parameter_set_id; |
| 52 | 54 |
| 53 int chroma_format_idc; | 55 int chroma_format_idc; |
| 54 bool separate_colour_plane_flag; | 56 bool separate_colour_plane_flag; |
| 55 int bit_depth_luma_minus8; | 57 int bit_depth_luma_minus8; |
| 56 int bit_depth_chroma_minus8; | 58 int bit_depth_chroma_minus8; |
| 57 bool qpprime_y_zero_transform_bypass_flag; | 59 bool qpprime_y_zero_transform_bypass_flag; |
| 58 | 60 |
| 59 bool seq_scaling_matrix_present_flag; | 61 bool seq_scaling_matrix_present_flag; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 77 bool direct_8x8_inference_flag; | 79 bool direct_8x8_inference_flag; |
| 78 bool frame_cropping_flag; | 80 bool frame_cropping_flag; |
| 79 int frame_crop_left_offset; | 81 int frame_crop_left_offset; |
| 80 int frame_crop_right_offset; | 82 int frame_crop_right_offset; |
| 81 int frame_crop_top_offset; | 83 int frame_crop_top_offset; |
| 82 int frame_crop_bottom_offset; | 84 int frame_crop_bottom_offset; |
| 83 bool vui_parameters_present_flag; | 85 bool vui_parameters_present_flag; |
| 84 int chroma_array_type; | 86 int chroma_array_type; |
| 85 }; | 87 }; |
| 86 | 88 |
| 87 struct H264PPS { | 89 struct CONTENT_EXPORT H264PPS { |
| 88 H264PPS(); | 90 H264PPS(); |
| 89 | 91 |
| 90 int pic_parameter_set_id; | 92 int pic_parameter_set_id; |
| 91 int seq_parameter_set_id; | 93 int seq_parameter_set_id; |
| 92 bool entropy_coding_mode_flag; | 94 bool entropy_coding_mode_flag; |
| 93 bool bottom_field_pic_order_in_frame_present_flag; | 95 bool bottom_field_pic_order_in_frame_present_flag; |
| 94 int num_slice_groups_minus1; | 96 int num_slice_groups_minus1; |
| 95 // TODO(posciak): Slice groups not implemented, could be added at some point. | 97 // TODO(posciak): Slice groups not implemented, could be added at some point. |
| 96 int num_ref_idx_l0_default_active_minus1; | 98 int num_ref_idx_l0_default_active_minus1; |
| 97 int num_ref_idx_l1_default_active_minus1; | 99 int num_ref_idx_l1_default_active_minus1; |
| 98 bool weighted_pred_flag; | 100 bool weighted_pred_flag; |
| 99 int weighted_bipred_idc; | 101 int weighted_bipred_idc; |
| 100 int pic_init_qp_minus26; | 102 int pic_init_qp_minus26; |
| 101 int pic_init_qs_minus26; | 103 int pic_init_qs_minus26; |
| 102 int chroma_qp_index_offset; | 104 int chroma_qp_index_offset; |
| 103 bool deblocking_filter_control_present_flag; | 105 bool deblocking_filter_control_present_flag; |
| 104 bool constrained_intra_pred_flag; | 106 bool constrained_intra_pred_flag; |
| 105 bool redundant_pic_cnt_present_flag; | 107 bool redundant_pic_cnt_present_flag; |
| 106 bool transform_8x8_mode_flag; | 108 bool transform_8x8_mode_flag; |
| 107 | 109 |
| 108 bool pic_scaling_matrix_present_flag; | 110 bool pic_scaling_matrix_present_flag; |
| 109 int scaling_list4x4[6][kH264ScalingList4x4Length]; | 111 int scaling_list4x4[6][kH264ScalingList4x4Length]; |
| 110 int scaling_list8x8[6][kH264ScalingList8x8Length]; | 112 int scaling_list8x8[6][kH264ScalingList8x8Length]; |
| 111 | 113 |
| 112 int second_chroma_qp_index_offset; | 114 int second_chroma_qp_index_offset; |
| 113 }; | 115 }; |
| 114 | 116 |
| 115 struct H264ModificationOfPicNum { | 117 struct CONTENT_EXPORT H264ModificationOfPicNum { |
| 116 int modification_of_pic_nums_idc; | 118 int modification_of_pic_nums_idc; |
| 117 union { | 119 union { |
| 118 int abs_diff_pic_num_minus1; | 120 int abs_diff_pic_num_minus1; |
| 119 int long_term_pic_num; | 121 int long_term_pic_num; |
| 120 }; | 122 }; |
| 121 }; | 123 }; |
| 122 | 124 |
| 123 struct H264WeightingFactors { | 125 struct CONTENT_EXPORT H264WeightingFactors { |
| 124 bool luma_weight_flag; | 126 bool luma_weight_flag; |
| 125 bool chroma_weight_flag; | 127 bool chroma_weight_flag; |
| 126 int luma_weight[32]; | 128 int luma_weight[32]; |
| 127 int luma_offset[32]; | 129 int luma_offset[32]; |
| 128 int chroma_weight[32][2]; | 130 int chroma_weight[32][2]; |
| 129 int chroma_offset[32][2]; | 131 int chroma_offset[32][2]; |
| 130 }; | 132 }; |
| 131 | 133 |
| 132 struct H264DecRefPicMarking { | 134 struct CONTENT_EXPORT H264DecRefPicMarking { |
| 133 int memory_mgmnt_control_operation; | 135 int memory_mgmnt_control_operation; |
| 134 int difference_of_pic_nums_minus1; | 136 int difference_of_pic_nums_minus1; |
| 135 int long_term_pic_num; | 137 int long_term_pic_num; |
| 136 int long_term_frame_idx; | 138 int long_term_frame_idx; |
| 137 int max_long_term_frame_idx_plus1; | 139 int max_long_term_frame_idx_plus1; |
| 138 }; | 140 }; |
| 139 | 141 |
| 140 struct H264SliceHeader { | 142 struct CONTENT_EXPORT H264SliceHeader { |
| 141 H264SliceHeader(); | 143 H264SliceHeader(); |
| 142 | 144 |
| 143 enum { | 145 enum { |
| 144 kRefListSize = 32, | 146 kRefListSize = 32, |
| 145 kRefListModSize = kRefListSize | 147 kRefListModSize = kRefListSize |
| 146 }; | 148 }; |
| 147 | 149 |
| 148 enum Type { | 150 enum Type { |
| 149 kPSlice = 0, | 151 kPSlice = 0, |
| 150 kBSlice = 1, | 152 kBSlice = 1, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 int payload_size; | 233 int payload_size; |
| 232 union { | 234 union { |
| 233 // Placeholder; in future more supported types will contribute to more | 235 // Placeholder; in future more supported types will contribute to more |
| 234 // union members here. | 236 // union members here. |
| 235 H264SEIRecoveryPoint recovery_point; | 237 H264SEIRecoveryPoint recovery_point; |
| 236 }; | 238 }; |
| 237 }; | 239 }; |
| 238 | 240 |
| 239 // Class to parse an Annex-B H.264 stream, | 241 // Class to parse an Annex-B H.264 stream, |
| 240 // as specified in chapters 7 and Annex B of the H.264 spec. | 242 // as specified in chapters 7 and Annex B of the H.264 spec. |
| 241 class H264Parser { | 243 class CONTENT_EXPORT H264Parser { |
| 242 public: | 244 public: |
| 243 enum Result { | 245 enum Result { |
| 244 kOk, | 246 kOk, |
| 245 kInvalidStream, // error in stream | 247 kInvalidStream, // error in stream |
| 246 kUnsupportedStream, // stream not supported by the parser | 248 kUnsupportedStream, // stream not supported by the parser |
| 247 kEOStream, // end of stream | 249 kEOStream, // end of stream |
| 248 }; | 250 }; |
| 249 | 251 |
| 250 H264Parser(); | 252 H264Parser(); |
| 251 ~H264Parser(); | 253 ~H264Parser(); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 typedef std::map<int, H264PPS*> PPSById; | 399 typedef std::map<int, H264PPS*> PPSById; |
| 398 SPSById active_SPSes_; | 400 SPSById active_SPSes_; |
| 399 PPSById active_PPSes_; | 401 PPSById active_PPSes_; |
| 400 | 402 |
| 401 DISALLOW_COPY_AND_ASSIGN(H264Parser); | 403 DISALLOW_COPY_AND_ASSIGN(H264Parser); |
| 402 }; | 404 }; |
| 403 | 405 |
| 404 } // namespace content | 406 } // namespace content |
| 405 | 407 |
| 406 #endif // CONTENT_COMMON_GPU_MEDIA_H264_PARSER_H_ | 408 #endif // CONTENT_COMMON_GPU_MEDIA_H264_PARSER_H_ |
| OLD | NEW |