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

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

Issue 2754543005: Revert of Save width/height of SPS nalus and restore them on the first packet of an IDR. (Closed)
Patch Set: Created 3 years, 9 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 27 matching lines...) Expand all
38 const RTPVideoHeaderH264& codec_header = video_header.codecHeader.H264; 38 const RTPVideoHeaderH264& codec_header = video_header.codecHeader.H264;
39 39
40 // Packets that only contains SPS/PPS are not decodable by themselves, and 40 // Packets that only contains SPS/PPS are not decodable by themselves, and
41 // to avoid frames being created containing only these two nalus we don't 41 // to avoid frames being created containing only these two nalus we don't
42 // insert them into the PacketBuffer. Instead we save the SPS/PPS and 42 // insert them into the PacketBuffer. Instead we save the SPS/PPS and
43 // prepend the bitstream of first packet of an IDR referring to the 43 // prepend the bitstream of first packet of an IDR referring to the
44 // corresponding SPS/PPS id. 44 // corresponding SPS/PPS id.
45 bool insert_packet = codec_header.nalus_length == 0 ? true : false; 45 bool insert_packet = codec_header.nalus_length == 0 ? true : false;
46 46
47 int pps_id = -1; 47 int pps_id = -1;
48 int sps_id = -1;
49 size_t required_size = 0; 48 size_t required_size = 0;
50 for (size_t i = 0; i < codec_header.nalus_length; ++i) { 49 for (size_t i = 0; i < codec_header.nalus_length; ++i) {
51 const NaluInfo& nalu = codec_header.nalus[i]; 50 const NaluInfo& nalu = codec_header.nalus[i];
52 switch (nalu.type) { 51 switch (nalu.type) {
53 case H264::NaluType::kSps: { 52 case H264::NaluType::kSps: {
54 // Save SPS. 53 // Save SPS.
55 sps_data_[nalu.sps_id].size = nalu.size; 54 sps_data_[nalu.sps_id].size = nalu.size;
56 sps_data_[nalu.sps_id].data.reset(new uint8_t[nalu.size]); 55 sps_data_[nalu.sps_id].data.reset(new uint8_t[nalu.size]);
57 memcpy(sps_data_[nalu.sps_id].data.get(), data + nalu.offset, 56 memcpy(sps_data_[nalu.sps_id].data.get(), data + nalu.offset,
58 nalu.size); 57 nalu.size);
59 sps_data_[nalu.sps_id].width = packet->width;
60 sps_data_[nalu.sps_id].height = packet->height;
61 break; 58 break;
62 } 59 }
63 case H264::NaluType::kPps: { 60 case H264::NaluType::kPps: {
64 // Save PPS. 61 // Save PPS.
65 pps_data_[nalu.pps_id].sps_id = nalu.sps_id; 62 pps_data_[nalu.pps_id].sps_id = nalu.sps_id;
66 pps_data_[nalu.pps_id].size = nalu.size; 63 pps_data_[nalu.pps_id].size = nalu.size;
67 pps_data_[nalu.pps_id].data.reset(new uint8_t[nalu.size]); 64 pps_data_[nalu.pps_id].data.reset(new uint8_t[nalu.size]);
68 memcpy(pps_data_[nalu.pps_id].data.get(), data + nalu.offset, 65 memcpy(pps_data_[nalu.pps_id].data.get(), data + nalu.offset,
69 nalu.size); 66 nalu.size);
70 break; 67 break;
71 } 68 }
72 case H264::NaluType::kIdr: { 69 case H264::NaluType::kIdr: {
73 // If this is the first packet of an IDR, make sure we have the required 70 // If this is the first packet of an IDR, make sure we have the required
74 // SPS/PPS and also calculate how much extra space we need in the buffer 71 // SPS/PPS and also calculate how much extra space we need in the buffer
75 // to prepend the SPS/PPS to the bitstream with start codes. 72 // to prepend the SPS/PPS to the bitstream with start codes.
76 if (video_header.is_first_packet_in_frame) { 73 if (video_header.is_first_packet_in_frame) {
77 if (nalu.pps_id == -1) { 74 if (nalu.pps_id == -1) {
78 LOG(LS_WARNING) << "No PPS id in IDR nalu."; 75 LOG(LS_WARNING) << "No PPS id in IDR nalu.";
79 return kRequestKeyframe; 76 return kRequestKeyframe;
80 } 77 }
81 78
82 auto pps = pps_data_.find(nalu.pps_id); 79 auto pps = pps_data_.find(nalu.pps_id);
83 if (pps == pps_data_.end()) { 80 if (pps == pps_data_.end()) {
84 LOG(LS_WARNING) << "No PPS with id << " << nalu.pps_id 81 LOG(LS_WARNING) << "No PPS with id << " << nalu.pps_id
85 << " received"; 82 << " received";
86 return kRequestKeyframe; 83 return kRequestKeyframe;
87 } 84 }
88 85
89 sps_id = pps->second.sps_id; 86 auto sps = sps_data_.find(pps->second.sps_id);
90 auto sps = sps_data_.find(sps_id);
91 if (sps == sps_data_.end()) { 87 if (sps == sps_data_.end()) {
92 LOG(LS_WARNING) << "No SPS with id << " 88 LOG(LS_WARNING) << "No SPS with id << "
93 << pps_data_[nalu.pps_id].sps_id << " received"; 89 << pps_data_[nalu.pps_id].sps_id << " received";
94 return kRequestKeyframe; 90 return kRequestKeyframe;
95 } 91 }
96 92
97 pps_id = nalu.pps_id; 93 pps_id = nalu.pps_id;
98 required_size += pps->second.size + sizeof(start_code_h264); 94 required_size += pps->second.size + sizeof(start_code_h264);
99 required_size += sps->second.size + sizeof(start_code_h264); 95 required_size += sps->second.size + sizeof(start_code_h264);
100 } 96 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 nalu_ptr += segment_length; 170 nalu_ptr += segment_length;
175 } 171 }
176 } else { 172 } else {
177 if (video_header.is_first_packet_in_frame) { 173 if (video_header.is_first_packet_in_frame) {
178 memcpy(insert_at, start_code_h264, sizeof(start_code_h264)); 174 memcpy(insert_at, start_code_h264, sizeof(start_code_h264));
179 insert_at += sizeof(start_code_h264); 175 insert_at += sizeof(start_code_h264);
180 } 176 }
181 memcpy(insert_at, data, data_size); 177 memcpy(insert_at, data, data_size);
182 } 178 }
183 179
184 packet->width = sps_data_[sps_id].width;
185 packet->height = sps_data_[sps_id].height;
186 packet->dataPtr = buffer; 180 packet->dataPtr = buffer;
187 packet->sizeBytes = required_size; 181 packet->sizeBytes = required_size;
188 return kInsert; 182 return kInsert;
189 } 183 }
190 184
191 void H264SpsPpsTracker::InsertSpsPpsNalus(const std::vector<uint8_t>& sps, 185 void H264SpsPpsTracker::InsertSpsPpsNalus(const std::vector<uint8_t>& sps,
192 const std::vector<uint8_t>& pps) { 186 const std::vector<uint8_t>& pps) {
193 constexpr size_t kNaluHeaderOffset = 1; 187 constexpr size_t kNaluHeaderOffset = 1;
194 if (sps.size() < kNaluHeaderOffset) { 188 if (sps.size() < kNaluHeaderOffset) {
195 LOG(LS_WARNING) << "SPS size " << sps.size() << " is smaller than " 189 LOG(LS_WARNING) << "SPS size " << sps.size() << " is smaller than "
(...skipping 25 matching lines...) Expand all
221 if (!parsed_pps) { 215 if (!parsed_pps) {
222 LOG(LS_WARNING) << "Failed to parse PPS."; 216 LOG(LS_WARNING) << "Failed to parse PPS.";
223 } 217 }
224 218
225 if (!parsed_pps || !parsed_sps) { 219 if (!parsed_pps || !parsed_sps) {
226 return; 220 return;
227 } 221 }
228 222
229 SpsInfo sps_info; 223 SpsInfo sps_info;
230 sps_info.size = sps.size(); 224 sps_info.size = sps.size();
231 sps_info.width = parsed_sps->width;
232 sps_info.height = parsed_sps->height;
233 uint8_t* sps_data = new uint8_t[sps_info.size]; 225 uint8_t* sps_data = new uint8_t[sps_info.size];
234 memcpy(sps_data, sps.data(), sps_info.size); 226 memcpy(sps_data, sps.data(), sps_info.size);
235 sps_info.data.reset(sps_data); 227 sps_info.data.reset(sps_data);
236 sps_data_[parsed_sps->id] = std::move(sps_info); 228 sps_data_[parsed_sps->id] = std::move(sps_info);
237 229
238 PpsInfo pps_info; 230 PpsInfo pps_info;
239 pps_info.size = pps.size(); 231 pps_info.size = pps.size();
240 pps_info.sps_id = parsed_pps->sps_id; 232 pps_info.sps_id = parsed_pps->sps_id;
241 uint8_t* pps_data = new uint8_t[pps_info.size]; 233 uint8_t* pps_data = new uint8_t[pps_info.size];
242 memcpy(pps_data, pps.data(), pps_info.size); 234 memcpy(pps_data, pps.data(), pps_info.size);
243 pps_info.data.reset(pps_data); 235 pps_info.data.reset(pps_data);
244 pps_data_[parsed_pps->id] = std::move(pps_info); 236 pps_data_[parsed_pps->id] = std::move(pps_info);
245 237
246 LOG(LS_INFO) << "Inserted SPS id " << parsed_sps->id << " and PPS id " 238 LOG(LS_INFO) << "Inserted SPS id " << parsed_sps->id << " and PPS id "
247 << parsed_pps->id << " (referencing SPS " << parsed_pps->sps_id 239 << parsed_pps->id << " (referencing SPS " << parsed_pps->sps_id
248 << ")"; 240 << ")";
249 } 241 }
250 242
251 } // namespace video_coding 243 } // namespace video_coding
252 } // 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