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 "media/filters/h264_parser.h" | 5 #include "media/filters/h264_parser.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/numerics/safe_math.h" | 12 #include "base/numerics/safe_math.h" |
13 #include "base/stl_util.h" | |
14 #include "media/base/decrypt_config.h" | 13 #include "media/base/decrypt_config.h" |
15 #include "ui/gfx/geometry/rect.h" | 14 #include "ui/gfx/geometry/rect.h" |
16 #include "ui/gfx/geometry/size.h" | 15 #include "ui/gfx/geometry/size.h" |
17 | 16 |
18 namespace media { | 17 namespace media { |
19 | 18 |
20 bool H264SliceHeader::IsPSlice() const { | 19 bool H264SliceHeader::IsPSlice() const { |
21 return (slice_type % 5 == kPSlice); | 20 return (slice_type % 5 == kPSlice); |
22 } | 21 } |
23 | 22 |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 0, 1, 11, 11, 11, 33, 11, 11, 11, 33, 11, 11, 33, 99, 3, 2, 1 | 198 0, 1, 11, 11, 11, 33, 11, 11, 11, 33, 11, 11, 33, 99, 3, 2, 1 |
200 }; | 199 }; |
201 static_assert(arraysize(kTableSarWidth) == arraysize(kTableSarHeight), | 200 static_assert(arraysize(kTableSarWidth) == arraysize(kTableSarHeight), |
202 "sar tables must have the same size"); | 201 "sar tables must have the same size"); |
203 | 202 |
204 H264Parser::H264Parser() { | 203 H264Parser::H264Parser() { |
205 Reset(); | 204 Reset(); |
206 } | 205 } |
207 | 206 |
208 H264Parser::~H264Parser() { | 207 H264Parser::~H264Parser() { |
209 base::STLDeleteValues(&active_SPSes_); | |
210 base::STLDeleteValues(&active_PPSes_); | |
211 } | 208 } |
212 | 209 |
213 void H264Parser::Reset() { | 210 void H264Parser::Reset() { |
214 stream_ = NULL; | 211 stream_ = NULL; |
215 bytes_left_ = 0; | 212 bytes_left_ = 0; |
216 encrypted_ranges_.clear(); | 213 encrypted_ranges_.clear(); |
217 } | 214 } |
218 | 215 |
219 void H264Parser::SetStream(const uint8_t* stream, off_t stream_size) { | 216 void H264Parser::SetStream(const uint8_t* stream, off_t stream_size) { |
220 std::vector<SubsampleEntry> subsamples; | 217 std::vector<SubsampleEntry> subsamples; |
(...skipping 23 matching lines...) Expand all Loading... |
244 } | 241 } |
245 } | 242 } |
246 | 243 |
247 const H264PPS* H264Parser::GetPPS(int pps_id) const { | 244 const H264PPS* H264Parser::GetPPS(int pps_id) const { |
248 auto it = active_PPSes_.find(pps_id); | 245 auto it = active_PPSes_.find(pps_id); |
249 if (it == active_PPSes_.end()) { | 246 if (it == active_PPSes_.end()) { |
250 DVLOG(1) << "Requested a nonexistent PPS id " << pps_id; | 247 DVLOG(1) << "Requested a nonexistent PPS id " << pps_id; |
251 return nullptr; | 248 return nullptr; |
252 } | 249 } |
253 | 250 |
254 return it->second; | 251 return it->second.get(); |
255 } | 252 } |
256 | 253 |
257 const H264SPS* H264Parser::GetSPS(int sps_id) const { | 254 const H264SPS* H264Parser::GetSPS(int sps_id) const { |
258 auto it = active_SPSes_.find(sps_id); | 255 auto it = active_SPSes_.find(sps_id); |
259 if (it == active_SPSes_.end()) { | 256 if (it == active_SPSes_.end()) { |
260 DVLOG(1) << "Requested a nonexistent SPS id " << sps_id; | 257 DVLOG(1) << "Requested a nonexistent SPS id " << sps_id; |
261 return nullptr; | 258 return nullptr; |
262 } | 259 } |
263 | 260 |
264 return it->second; | 261 return it->second.get(); |
265 } | 262 } |
266 | 263 |
267 static inline bool IsStartCode(const uint8_t* data) { | 264 static inline bool IsStartCode(const uint8_t* data) { |
268 return data[0] == 0x00 && data[1] == 0x00 && data[2] == 0x01; | 265 return data[0] == 0x00 && data[1] == 0x00 && data[2] == 0x01; |
269 } | 266 } |
270 | 267 |
271 // static | 268 // static |
272 bool H264Parser::FindStartCode(const uint8_t* data, | 269 bool H264Parser::FindStartCode(const uint8_t* data, |
273 off_t data_size, | 270 off_t data_size, |
274 off_t* offset, | 271 off_t* offset, |
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
992 READ_BOOL_OR_RETURN(&sps->vui_parameters_present_flag); | 989 READ_BOOL_OR_RETURN(&sps->vui_parameters_present_flag); |
993 if (sps->vui_parameters_present_flag) { | 990 if (sps->vui_parameters_present_flag) { |
994 DVLOG(4) << "VUI parameters present"; | 991 DVLOG(4) << "VUI parameters present"; |
995 res = ParseVUIParameters(sps.get()); | 992 res = ParseVUIParameters(sps.get()); |
996 if (res != kOk) | 993 if (res != kOk) |
997 return res; | 994 return res; |
998 } | 995 } |
999 | 996 |
1000 // If an SPS with the same id already exists, replace it. | 997 // If an SPS with the same id already exists, replace it. |
1001 *sps_id = sps->seq_parameter_set_id; | 998 *sps_id = sps->seq_parameter_set_id; |
1002 delete active_SPSes_[*sps_id]; | 999 active_SPSes_[*sps_id] = std::move(sps); |
1003 active_SPSes_[*sps_id] = sps.release(); | |
1004 | 1000 |
1005 return kOk; | 1001 return kOk; |
1006 } | 1002 } |
1007 | 1003 |
1008 H264Parser::Result H264Parser::ParsePPS(int* pps_id) { | 1004 H264Parser::Result H264Parser::ParsePPS(int* pps_id) { |
1009 // See 7.4.2.2. | 1005 // See 7.4.2.2. |
1010 const H264SPS* sps; | 1006 const H264SPS* sps; |
1011 Result res; | 1007 Result res; |
1012 | 1008 |
1013 *pps_id = -1; | 1009 *pps_id = -1; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1068 res = ParsePPSScalingLists(*sps, pps.get()); | 1064 res = ParsePPSScalingLists(*sps, pps.get()); |
1069 if (res != kOk) | 1065 if (res != kOk) |
1070 return res; | 1066 return res; |
1071 } | 1067 } |
1072 | 1068 |
1073 READ_SE_OR_RETURN(&pps->second_chroma_qp_index_offset); | 1069 READ_SE_OR_RETURN(&pps->second_chroma_qp_index_offset); |
1074 } | 1070 } |
1075 | 1071 |
1076 // If a PPS with the same id already exists, replace it. | 1072 // If a PPS with the same id already exists, replace it. |
1077 *pps_id = pps->pic_parameter_set_id; | 1073 *pps_id = pps->pic_parameter_set_id; |
1078 delete active_PPSes_[*pps_id]; | 1074 active_PPSes_[*pps_id] = std::move(pps); |
1079 active_PPSes_[*pps_id] = pps.release(); | |
1080 | 1075 |
1081 return kOk; | 1076 return kOk; |
1082 } | 1077 } |
1083 | 1078 |
1084 H264Parser::Result H264Parser::ParseRefPicListModification( | 1079 H264Parser::Result H264Parser::ParseRefPicListModification( |
1085 int num_ref_idx_active_minus1, | 1080 int num_ref_idx_active_minus1, |
1086 H264ModificationOfPicNum* ref_list_mods) { | 1081 H264ModificationOfPicNum* ref_list_mods) { |
1087 H264ModificationOfPicNum* pic_num_mod; | 1082 H264ModificationOfPicNum* pic_num_mod; |
1088 | 1083 |
1089 if (num_ref_idx_active_minus1 >= 32) | 1084 if (num_ref_idx_active_minus1 >= 32) |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1458 | 1453 |
1459 default: | 1454 default: |
1460 DVLOG(4) << "Unsupported SEI message"; | 1455 DVLOG(4) << "Unsupported SEI message"; |
1461 break; | 1456 break; |
1462 } | 1457 } |
1463 | 1458 |
1464 return kOk; | 1459 return kOk; |
1465 } | 1460 } |
1466 | 1461 |
1467 } // namespace media | 1462 } // namespace media |
OLD | NEW |