Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(415)

Side by Side Diff: webrtc/modules/video_coding/h264_sps_pps_tracker.cc

Issue 2638933002: H264SpsPpsTracker.InsertSpsPpsNalus() should accept Nalus with header. (Closed)
Patch Set: Remove reundant log msg. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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.";
194 return; 220 return;
195 } 221 }
196 222
197 SpsInfo sps_info; 223 SpsInfo sps_info;
198 sps_info.size = sps.size(); 224 sps_info.size = sps.size();
199 uint8_t* sps_data = new uint8_t[sps_info.size]; 225 uint8_t* sps_data = new uint8_t[sps_info.size];
200 memcpy(sps_data, sps.data(), sps_info.size); 226 memcpy(sps_data, sps.data(), sps_info.size);
201 sps_info.data.reset(sps_data); 227 sps_info.data.reset(sps_data);
202 sps_data_[parsed_sps->id] = std::move(sps_info); 228 sps_data_[parsed_sps->id] = std::move(sps_info);
203 229
204 PpsInfo pps_info; 230 PpsInfo pps_info;
205 pps_info.size = pps.size(); 231 pps_info.size = pps.size();
206 pps_info.sps_id = parsed_pps->sps_id; 232 pps_info.sps_id = parsed_pps->sps_id;
207 uint8_t* pps_data = new uint8_t[pps_info.size]; 233 uint8_t* pps_data = new uint8_t[pps_info.size];
208 memcpy(pps_data, pps.data(), pps_info.size); 234 memcpy(pps_data, pps.data(), pps_info.size);
209 pps_info.data.reset(pps_data); 235 pps_info.data.reset(pps_data);
210 pps_data_[parsed_pps->id] = std::move(pps_info); 236 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 << ")";
211 } 241 }
212 242
213 } // namespace video_coding 243 } // namespace video_coding
214 } // namespace webrtc 244 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/h264_sps_pps_tracker.h ('k') | webrtc/modules/video_coding/h264_sps_pps_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698