OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 insert_at += sizeof(start_code_h264); | 175 insert_at += sizeof(start_code_h264); |
176 } | 176 } |
177 memcpy(insert_at, data, data_size); | 177 memcpy(insert_at, data, data_size); |
178 } | 178 } |
179 | 179 |
180 packet->dataPtr = buffer; | 180 packet->dataPtr = buffer; |
181 packet->sizeBytes = required_size; | 181 packet->sizeBytes = required_size; |
182 return kInsert; | 182 return kInsert; |
183 } | 183 } |
184 | 184 |
185 void H264SpsPpsTracker::InsertSpsPpsNalus(const std::vector<uint8_t>& sps, | 185 void H264SpsPpsTracker::InsertSpsPps(const std::vector<uint8_t>& sps, |
186 const std::vector<uint8_t>& pps) { | 186 const std::vector<uint8_t>& pps) { |
187 constexpr size_t kNaluHeaderOffset = 1; | 187 rtc::Optional<SpsParser::SpsState> parsed_sps = |
188 if (sps.size() < kNaluHeaderOffset) { | 188 SpsParser::ParseSps(sps.data(), sps.size()); |
189 LOG(LS_WARNING) << "SPS size " << sps.size() << " is smaller than " | 189 rtc::Optional<PpsParser::PpsState> parsed_pps = |
190 << kNaluHeaderOffset; | 190 PpsParser::ParsePps(pps.data(), pps.size()); |
191 return; | |
192 } | |
193 if ((sps[0] & 0x1f) != H264::NaluType::kSps) { | |
194 LOG(LS_WARNING) << "SPS Nalu header missing"; | |
195 return; | |
196 } | |
197 if (pps.size() < kNaluHeaderOffset) { | |
198 LOG(LS_WARNING) << "PPS size " << pps.size() << " is smaller than " | |
199 << kNaluHeaderOffset; | |
200 return; | |
201 } | |
202 if ((pps[0] & 0x1f) != H264::NaluType::kPps) { | |
203 LOG(LS_WARNING) << "SPS Nalu header missing"; | |
204 return; | |
205 } | |
206 rtc::Optional<SpsParser::SpsState> parsed_sps = SpsParser::ParseSps( | |
207 sps.data() + kNaluHeaderOffset, sps.size() - kNaluHeaderOffset); | |
208 rtc::Optional<PpsParser::PpsState> parsed_pps = PpsParser::ParsePps( | |
209 pps.data() + kNaluHeaderOffset, pps.size() - kNaluHeaderOffset); | |
210 | |
211 if (!parsed_sps) { | |
212 LOG(LS_WARNING) << "Failed to parse SPS."; | |
213 } | |
214 | |
215 if (!parsed_pps) { | |
216 LOG(LS_WARNING) << "Failed to parse PPS."; | |
217 } | |
218 | 191 |
219 if (!parsed_pps || !parsed_sps) { | 192 if (!parsed_pps || !parsed_sps) { |
| 193 LOG(LS_WARNING) << "Failed to parse SPS or PPS parameters."; |
220 return; | 194 return; |
221 } | 195 } |
222 | 196 |
223 SpsInfo sps_info; | 197 SpsInfo sps_info; |
224 sps_info.size = sps.size(); | 198 sps_info.size = sps.size(); |
225 uint8_t* sps_data = new uint8_t[sps_info.size]; | 199 uint8_t* sps_data = new uint8_t[sps_info.size]; |
226 memcpy(sps_data, sps.data(), sps_info.size); | 200 memcpy(sps_data, sps.data(), sps_info.size); |
227 sps_info.data.reset(sps_data); | 201 sps_info.data.reset(sps_data); |
228 sps_data_[parsed_sps->id] = std::move(sps_info); | 202 sps_data_[parsed_sps->id] = std::move(sps_info); |
229 | 203 |
230 PpsInfo pps_info; | 204 PpsInfo pps_info; |
231 pps_info.size = pps.size(); | 205 pps_info.size = pps.size(); |
232 pps_info.sps_id = parsed_pps->sps_id; | 206 pps_info.sps_id = parsed_pps->sps_id; |
233 uint8_t* pps_data = new uint8_t[pps_info.size]; | 207 uint8_t* pps_data = new uint8_t[pps_info.size]; |
234 memcpy(pps_data, pps.data(), pps_info.size); | 208 memcpy(pps_data, pps.data(), pps_info.size); |
235 pps_info.data.reset(pps_data); | 209 pps_info.data.reset(pps_data); |
236 pps_data_[parsed_pps->id] = std::move(pps_info); | 210 pps_data_[parsed_pps->id] = std::move(pps_info); |
237 | |
238 LOG(LS_INFO) << "Inserted SPS id " << parsed_sps->id << " and PPS id " | |
239 << parsed_pps->id << " (referencing SPS " << parsed_pps->sps_id | |
240 << ")"; | |
241 } | 211 } |
242 | 212 |
243 } // namespace video_coding | 213 } // namespace video_coding |
244 } // namespace webrtc | 214 } // namespace webrtc |
OLD | NEW |