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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 const uint8* stream_end = stream_ + bytes_left_; | 152 const uint8* stream_end = stream_ + bytes_left_; |
153 for (size_t i = 0; i < subsamples.size() && start < stream_end; ++i) { | 153 for (size_t i = 0; i < subsamples.size() && start < stream_end; ++i) { |
154 start += subsamples[i].clear_bytes; | 154 start += subsamples[i].clear_bytes; |
155 | 155 |
156 const uint8* end = std::min(start + subsamples[i].cypher_bytes, stream_end); | 156 const uint8* end = std::min(start + subsamples[i].cypher_bytes, stream_end); |
157 encrypted_ranges_.Add(start, end); | 157 encrypted_ranges_.Add(start, end); |
158 start = end; | 158 start = end; |
159 } | 159 } |
160 } | 160 } |
161 | 161 |
162 const H264PPS* H264Parser::GetPPS(int pps_id) { | 162 const H264PPS* H264Parser::GetPPS(int pps_id) const { |
163 return active_PPSes_[pps_id]; | 163 auto it = active_PPSes_.find(pps_id); |
| 164 if (it == active_PPSes_.end()) { |
| 165 DVLOG(1) << "Requested a nonexistent PPS id " << pps_id; |
| 166 return nullptr; |
| 167 } |
| 168 |
| 169 return it->second; |
164 } | 170 } |
165 | 171 |
166 const H264SPS* H264Parser::GetSPS(int sps_id) { | 172 const H264SPS* H264Parser::GetSPS(int sps_id) const { |
167 return active_SPSes_[sps_id]; | 173 auto it = active_SPSes_.find(sps_id); |
| 174 if (it == active_SPSes_.end()) { |
| 175 DVLOG(1) << "Requested a nonexistent SPS id " << sps_id; |
| 176 return nullptr; |
| 177 } |
| 178 |
| 179 return it->second; |
168 } | 180 } |
169 | 181 |
170 static inline bool IsStartCode(const uint8* data) { | 182 static inline bool IsStartCode(const uint8* data) { |
171 return data[0] == 0x00 && data[1] == 0x00 && data[2] == 0x01; | 183 return data[0] == 0x00 && data[1] == 0x00 && data[2] == 0x01; |
172 } | 184 } |
173 | 185 |
174 // static | 186 // static |
175 bool H264Parser::FindStartCode(const uint8* data, off_t data_size, | 187 bool H264Parser::FindStartCode(const uint8* data, off_t data_size, |
176 off_t* offset, off_t* start_code_size) { | 188 off_t* offset, off_t* start_code_size) { |
177 DCHECK_GE(data_size, 0); | 189 DCHECK_GE(data_size, 0); |
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 for (int i = 0; i < sps->num_ref_frames_in_pic_order_cnt_cycle; ++i) { | 840 for (int i = 0; i < sps->num_ref_frames_in_pic_order_cnt_cycle; ++i) { |
829 READ_SE_OR_RETURN(&sps->offset_for_ref_frame[i]); | 841 READ_SE_OR_RETURN(&sps->offset_for_ref_frame[i]); |
830 sps->expected_delta_per_pic_order_cnt_cycle += | 842 sps->expected_delta_per_pic_order_cnt_cycle += |
831 sps->offset_for_ref_frame[i]; | 843 sps->offset_for_ref_frame[i]; |
832 } | 844 } |
833 } | 845 } |
834 | 846 |
835 READ_UE_OR_RETURN(&sps->max_num_ref_frames); | 847 READ_UE_OR_RETURN(&sps->max_num_ref_frames); |
836 READ_BOOL_OR_RETURN(&sps->gaps_in_frame_num_value_allowed_flag); | 848 READ_BOOL_OR_RETURN(&sps->gaps_in_frame_num_value_allowed_flag); |
837 | 849 |
838 if (sps->gaps_in_frame_num_value_allowed_flag) | |
839 return kUnsupportedStream; | |
840 | |
841 READ_UE_OR_RETURN(&sps->pic_width_in_mbs_minus1); | 850 READ_UE_OR_RETURN(&sps->pic_width_in_mbs_minus1); |
842 READ_UE_OR_RETURN(&sps->pic_height_in_map_units_minus1); | 851 READ_UE_OR_RETURN(&sps->pic_height_in_map_units_minus1); |
843 | 852 |
844 READ_BOOL_OR_RETURN(&sps->frame_mbs_only_flag); | 853 READ_BOOL_OR_RETURN(&sps->frame_mbs_only_flag); |
845 if (!sps->frame_mbs_only_flag) | 854 if (!sps->frame_mbs_only_flag) |
846 READ_BOOL_OR_RETURN(&sps->mb_adaptive_frame_field_flag); | 855 READ_BOOL_OR_RETURN(&sps->mb_adaptive_frame_field_flag); |
847 | 856 |
848 READ_BOOL_OR_RETURN(&sps->direct_8x8_inference_flag); | 857 READ_BOOL_OR_RETURN(&sps->direct_8x8_inference_flag); |
849 | 858 |
850 READ_BOOL_OR_RETURN(&sps->frame_cropping_flag); | 859 READ_BOOL_OR_RETURN(&sps->frame_cropping_flag); |
(...skipping 26 matching lines...) Expand all Loading... |
877 Result res; | 886 Result res; |
878 | 887 |
879 *pps_id = -1; | 888 *pps_id = -1; |
880 | 889 |
881 scoped_ptr<H264PPS> pps(new H264PPS()); | 890 scoped_ptr<H264PPS> pps(new H264PPS()); |
882 | 891 |
883 READ_UE_OR_RETURN(&pps->pic_parameter_set_id); | 892 READ_UE_OR_RETURN(&pps->pic_parameter_set_id); |
884 READ_UE_OR_RETURN(&pps->seq_parameter_set_id); | 893 READ_UE_OR_RETURN(&pps->seq_parameter_set_id); |
885 TRUE_OR_RETURN(pps->seq_parameter_set_id < 32); | 894 TRUE_OR_RETURN(pps->seq_parameter_set_id < 32); |
886 | 895 |
| 896 if (active_SPSes_.find(pps->seq_parameter_set_id) == active_SPSes_.end()) { |
| 897 DVLOG(1) << "Invalid stream, no SPS id: " << pps->seq_parameter_set_id; |
| 898 return kInvalidStream; |
| 899 } |
| 900 |
887 sps = GetSPS(pps->seq_parameter_set_id); | 901 sps = GetSPS(pps->seq_parameter_set_id); |
888 TRUE_OR_RETURN(sps); | 902 TRUE_OR_RETURN(sps); |
889 | 903 |
890 READ_BOOL_OR_RETURN(&pps->entropy_coding_mode_flag); | 904 READ_BOOL_OR_RETURN(&pps->entropy_coding_mode_flag); |
891 READ_BOOL_OR_RETURN(&pps->bottom_field_pic_order_in_frame_present_flag); | 905 READ_BOOL_OR_RETURN(&pps->bottom_field_pic_order_in_frame_present_flag); |
892 | 906 |
893 READ_UE_OR_RETURN(&pps->num_slice_groups_minus1); | 907 READ_UE_OR_RETURN(&pps->num_slice_groups_minus1); |
894 if (pps->num_slice_groups_minus1 > 1) { | 908 if (pps->num_slice_groups_minus1 > 1) { |
895 DVLOG(1) << "Slice groups not supported"; | 909 DVLOG(1) << "Slice groups not supported"; |
896 return kUnsupportedStream; | 910 return kUnsupportedStream; |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1319 | 1333 |
1320 default: | 1334 default: |
1321 DVLOG(4) << "Unsupported SEI message"; | 1335 DVLOG(4) << "Unsupported SEI message"; |
1322 break; | 1336 break; |
1323 } | 1337 } |
1324 | 1338 |
1325 return kOk; | 1339 return kOk; |
1326 } | 1340 } |
1327 | 1341 |
1328 } // namespace media | 1342 } // namespace media |
OLD | NEW |