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::InsertSpsPps(const std::vector<uint8_t>& sps, | 185 void H264SpsPpsTracker::InsertSpsPpsNalus(const std::vector<uint8_t>& sps, |
186 const std::vector<uint8_t>& pps) { | 186 const std::vector<uint8_t>& pps) { |
187 rtc::Optional<SpsParser::SpsState> parsed_sps = | 187 constexpr size_t kNaluHeaderOffset = 1; |
188 SpsParser::ParseSps(sps.data(), sps.size()); | 188 if (sps.size() < kNaluHeaderOffset) { |
189 rtc::Optional<PpsParser::PpsState> parsed_pps = | 189 LOG(LS_WARNING) << "SPS size " << sps.size() << " is smaller than " |
190 PpsParser::ParsePps(pps.data(), pps.size()); | 190 << kNaluHeaderOffset; |
| 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 } |
191 | 218 |
192 if (!parsed_pps || !parsed_sps) { | 219 if (!parsed_pps || !parsed_sps) { |
193 LOG(LS_WARNING) << "Failed to parse SPS or PPS parameters."; | 220 LOG(LS_WARNING) << "Failed to parse SPS or PPS parameters."; |
194 return; | 221 return; |
195 } | 222 } |
196 | 223 |
197 SpsInfo sps_info; | 224 SpsInfo sps_info; |
198 sps_info.size = sps.size(); | 225 sps_info.size = sps.size(); |
199 uint8_t* sps_data = new uint8_t[sps_info.size]; | 226 uint8_t* sps_data = new uint8_t[sps_info.size]; |
200 memcpy(sps_data, sps.data(), sps_info.size); | 227 memcpy(sps_data, sps.data(), sps_info.size); |
201 sps_info.data.reset(sps_data); | 228 sps_info.data.reset(sps_data); |
202 sps_data_[parsed_sps->id] = std::move(sps_info); | 229 sps_data_[parsed_sps->id] = std::move(sps_info); |
203 | 230 |
204 PpsInfo pps_info; | 231 PpsInfo pps_info; |
205 pps_info.size = pps.size(); | 232 pps_info.size = pps.size(); |
206 pps_info.sps_id = parsed_pps->sps_id; | 233 pps_info.sps_id = parsed_pps->sps_id; |
207 uint8_t* pps_data = new uint8_t[pps_info.size]; | 234 uint8_t* pps_data = new uint8_t[pps_info.size]; |
208 memcpy(pps_data, pps.data(), pps_info.size); | 235 memcpy(pps_data, pps.data(), pps_info.size); |
209 pps_info.data.reset(pps_data); | 236 pps_info.data.reset(pps_data); |
210 pps_data_[parsed_pps->id] = std::move(pps_info); | 237 pps_data_[parsed_pps->id] = std::move(pps_info); |
| 238 |
| 239 LOG(LS_INFO) << "Inserted SPS id " << parsed_sps->id << " and PPS id " |
| 240 << parsed_pps->id << " (referencing SPS " << parsed_pps->sps_id |
| 241 << ")"; |
211 } | 242 } |
212 | 243 |
213 } // namespace video_coding | 244 } // namespace video_coding |
214 } // namespace webrtc | 245 } // namespace webrtc |
OLD | NEW |