Chromium Code Reviews| 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 27 matching lines...) Expand all Loading... | |
| 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; | |
| 48 size_t required_size = 0; | 49 size_t required_size = 0; |
| 49 for (size_t i = 0; i < codec_header.nalus_length; ++i) { | 50 for (size_t i = 0; i < codec_header.nalus_length; ++i) { |
| 50 const NaluInfo& nalu = codec_header.nalus[i]; | 51 const NaluInfo& nalu = codec_header.nalus[i]; |
| 51 switch (nalu.type) { | 52 switch (nalu.type) { |
| 52 case H264::NaluType::kSps: { | 53 case H264::NaluType::kSps: { |
| 53 // Save SPS. | 54 // Save SPS. |
| 54 sps_data_[nalu.sps_id].size = nalu.size; | 55 sps_data_[nalu.sps_id].size = nalu.size; |
| 55 sps_data_[nalu.sps_id].data.reset(new uint8_t[nalu.size]); | 56 sps_data_[nalu.sps_id].data.reset(new uint8_t[nalu.size]); |
| 56 memcpy(sps_data_[nalu.sps_id].data.get(), data + nalu.offset, | 57 memcpy(sps_data_[nalu.sps_id].data.get(), data + nalu.offset, |
| 57 nalu.size); | 58 nalu.size); |
| 59 sps_data_[nalu.sps_id].width = packet->width; | |
| 60 sps_data_[nalu.sps_id].height = packet->height; | |
| 58 break; | 61 break; |
| 59 } | 62 } |
| 60 case H264::NaluType::kPps: { | 63 case H264::NaluType::kPps: { |
| 61 // Save PPS. | 64 // Save PPS. |
| 62 pps_data_[nalu.pps_id].sps_id = nalu.sps_id; | 65 pps_data_[nalu.pps_id].sps_id = nalu.sps_id; |
| 63 pps_data_[nalu.pps_id].size = nalu.size; | 66 pps_data_[nalu.pps_id].size = nalu.size; |
| 64 pps_data_[nalu.pps_id].data.reset(new uint8_t[nalu.size]); | 67 pps_data_[nalu.pps_id].data.reset(new uint8_t[nalu.size]); |
| 65 memcpy(pps_data_[nalu.pps_id].data.get(), data + nalu.offset, | 68 memcpy(pps_data_[nalu.pps_id].data.get(), data + nalu.offset, |
| 66 nalu.size); | 69 nalu.size); |
| 67 break; | 70 break; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 83 return kRequestKeyframe; | 86 return kRequestKeyframe; |
| 84 } | 87 } |
| 85 | 88 |
| 86 auto sps = sps_data_.find(pps->second.sps_id); | 89 auto sps = sps_data_.find(pps->second.sps_id); |
| 87 if (sps == sps_data_.end()) { | 90 if (sps == sps_data_.end()) { |
| 88 LOG(LS_WARNING) << "No SPS with id << " | 91 LOG(LS_WARNING) << "No SPS with id << " |
| 89 << pps_data_[nalu.pps_id].sps_id << " received"; | 92 << pps_data_[nalu.pps_id].sps_id << " received"; |
| 90 return kRequestKeyframe; | 93 return kRequestKeyframe; |
| 91 } | 94 } |
| 92 | 95 |
| 96 sps_id = pps->second.sps_id; | |
| 93 pps_id = nalu.pps_id; | 97 pps_id = nalu.pps_id; |
| 94 required_size += pps->second.size + sizeof(start_code_h264); | 98 required_size += pps->second.size + sizeof(start_code_h264); |
| 95 required_size += sps->second.size + sizeof(start_code_h264); | 99 required_size += sps->second.size + sizeof(start_code_h264); |
| 96 } | 100 } |
| 97 FALLTHROUGH(); | 101 FALLTHROUGH(); |
| 98 } | 102 } |
| 99 default: { | 103 default: { |
| 100 // Something other than an SPS/PPS nalu in this packet, then it should | 104 // Something other than an SPS/PPS nalu in this packet, then it should |
| 101 // be inserted into the PacketBuffer. | 105 // be inserted into the PacketBuffer. |
| 102 insert_packet = true; | 106 insert_packet = true; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 nalu_ptr += segment_length; | 174 nalu_ptr += segment_length; |
| 171 } | 175 } |
| 172 } else { | 176 } else { |
| 173 if (video_header.is_first_packet_in_frame) { | 177 if (video_header.is_first_packet_in_frame) { |
| 174 memcpy(insert_at, start_code_h264, sizeof(start_code_h264)); | 178 memcpy(insert_at, start_code_h264, sizeof(start_code_h264)); |
| 175 insert_at += sizeof(start_code_h264); | 179 insert_at += sizeof(start_code_h264); |
| 176 } | 180 } |
| 177 memcpy(insert_at, data, data_size); | 181 memcpy(insert_at, data, data_size); |
| 178 } | 182 } |
| 179 | 183 |
| 184 if (sps_data_[sps_id].width > 0 && sps_data_[sps_id].height) { | |
|
stefan-webrtc
2017/03/14 10:32:20
height > 0
Or, if you anyway initialize width/hei
philipel
2017/03/14 11:51:12
The problem is that I can't be certain that the SP
stefan-webrtc
2017/03/14 12:06:36
I'm fairly sure width/height is required in the sp
philipel
2017/03/14 13:52:41
I looked at the code and we only know the width/he
| |
| 185 packet->width = sps_data_[sps_id].width; | |
| 186 packet->height = sps_data_[sps_id].height; | |
| 187 } | |
| 188 | |
| 180 packet->dataPtr = buffer; | 189 packet->dataPtr = buffer; |
| 181 packet->sizeBytes = required_size; | 190 packet->sizeBytes = required_size; |
| 182 return kInsert; | 191 return kInsert; |
| 183 } | 192 } |
| 184 | 193 |
| 185 void H264SpsPpsTracker::InsertSpsPpsNalus(const std::vector<uint8_t>& sps, | 194 void H264SpsPpsTracker::InsertSpsPpsNalus(const std::vector<uint8_t>& sps, |
| 186 const std::vector<uint8_t>& pps) { | 195 const std::vector<uint8_t>& pps) { |
| 187 constexpr size_t kNaluHeaderOffset = 1; | 196 constexpr size_t kNaluHeaderOffset = 1; |
| 188 if (sps.size() < kNaluHeaderOffset) { | 197 if (sps.size() < kNaluHeaderOffset) { |
| 189 LOG(LS_WARNING) << "SPS size " << sps.size() << " is smaller than " | 198 LOG(LS_WARNING) << "SPS size " << sps.size() << " is smaller than " |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 pps_info.data.reset(pps_data); | 244 pps_info.data.reset(pps_data); |
| 236 pps_data_[parsed_pps->id] = std::move(pps_info); | 245 pps_data_[parsed_pps->id] = std::move(pps_info); |
| 237 | 246 |
| 238 LOG(LS_INFO) << "Inserted SPS id " << parsed_sps->id << " and PPS id " | 247 LOG(LS_INFO) << "Inserted SPS id " << parsed_sps->id << " and PPS id " |
| 239 << parsed_pps->id << " (referencing SPS " << parsed_pps->sps_id | 248 << parsed_pps->id << " (referencing SPS " << parsed_pps->sps_id |
| 240 << ")"; | 249 << ")"; |
| 241 } | 250 } |
| 242 | 251 |
| 243 } // namespace video_coding | 252 } // namespace video_coding |
| 244 } // namespace webrtc | 253 } // namespace webrtc |
| OLD | NEW |