| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 pps_data_[nalu.pps_id].size = nalu.size; | 63 pps_data_[nalu.pps_id].size = nalu.size; |
| 64 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]); |
| 65 memcpy(pps_data_[nalu.pps_id].data.get(), data + nalu.offset, | 65 memcpy(pps_data_[nalu.pps_id].data.get(), data + nalu.offset, |
| 66 nalu.size); | 66 nalu.size); |
| 67 break; | 67 break; |
| 68 } | 68 } |
| 69 case H264::NaluType::kIdr: { | 69 case H264::NaluType::kIdr: { |
| 70 // 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 |
| 71 // 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 |
| 72 // to prepend the SPS/PPS to the bitstream with start codes. | 72 // to prepend the SPS/PPS to the bitstream with start codes. |
| 73 if (video_header.isFirstPacket) { | 73 if (video_header.is_first_packet_in_frame) { |
| 74 if (nalu.pps_id == -1) { | 74 if (nalu.pps_id == -1) { |
| 75 LOG(LS_WARNING) << "No PPS id in IDR nalu."; | 75 LOG(LS_WARNING) << "No PPS id in IDR nalu."; |
| 76 return kRequestKeyframe; | 76 return kRequestKeyframe; |
| 77 } | 77 } |
| 78 | 78 |
| 79 auto pps = pps_data_.find(nalu.pps_id); | 79 auto pps = pps_data_.find(nalu.pps_id); |
| 80 if (pps == pps_data_.end()) { | 80 if (pps == pps_data_.end()) { |
| 81 LOG(LS_WARNING) << "No PPS with id << " << nalu.pps_id | 81 LOG(LS_WARNING) << "No PPS with id << " << nalu.pps_id |
| 82 << " received"; | 82 << " received"; |
| 83 return kRequestKeyframe; | 83 return kRequestKeyframe; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 104 } | 104 } |
| 105 } | 105 } |
| 106 | 106 |
| 107 if (!insert_packet) | 107 if (!insert_packet) |
| 108 return kDrop; | 108 return kDrop; |
| 109 | 109 |
| 110 // Calculate how much space we need for the rest of the bitstream. | 110 // Calculate how much space we need for the rest of the bitstream. |
| 111 if (codec_header.packetization_type == kH264StapA) { | 111 if (codec_header.packetization_type == kH264StapA) { |
| 112 const uint8_t* nalu_ptr = data + 1; | 112 const uint8_t* nalu_ptr = data + 1; |
| 113 while (nalu_ptr < data + data_size) { | 113 while (nalu_ptr < data + data_size) { |
| 114 RTC_DCHECK(video_header.isFirstPacket); | 114 RTC_DCHECK(video_header.is_first_packet_in_frame); |
| 115 required_size += sizeof(start_code_h264); | 115 required_size += sizeof(start_code_h264); |
| 116 | 116 |
| 117 // The first two bytes describe the length of a segment. | 117 // The first two bytes describe the length of a segment. |
| 118 uint16_t segment_length = nalu_ptr[0] << 8 | nalu_ptr[1]; | 118 uint16_t segment_length = nalu_ptr[0] << 8 | nalu_ptr[1]; |
| 119 nalu_ptr += 2; | 119 nalu_ptr += 2; |
| 120 | 120 |
| 121 required_size += segment_length; | 121 required_size += segment_length; |
| 122 nalu_ptr += segment_length; | 122 nalu_ptr += segment_length; |
| 123 } | 123 } |
| 124 } else { | 124 } else { |
| 125 if (video_header.isFirstPacket) | 125 if (video_header.is_first_packet_in_frame) |
| 126 required_size += sizeof(start_code_h264); | 126 required_size += sizeof(start_code_h264); |
| 127 required_size += data_size; | 127 required_size += data_size; |
| 128 } | 128 } |
| 129 | 129 |
| 130 // Then we copy to the new buffer. | 130 // Then we copy to the new buffer. |
| 131 uint8_t* buffer = new uint8_t[required_size]; | 131 uint8_t* buffer = new uint8_t[required_size]; |
| 132 uint8_t* insert_at = buffer; | 132 uint8_t* insert_at = buffer; |
| 133 | 133 |
| 134 // If pps_id != -1 then we have the SPS/PPS and they should be prepended | 134 // If pps_id != -1 then we have the SPS/PPS and they should be prepended |
| 135 // to the bitstream with start codes inserted. | 135 // to the bitstream with start codes inserted. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 163 if (copy_end > data_size) { | 163 if (copy_end > data_size) { |
| 164 delete[] buffer; | 164 delete[] buffer; |
| 165 return kDrop; | 165 return kDrop; |
| 166 } | 166 } |
| 167 | 167 |
| 168 memcpy(insert_at, nalu_ptr, segment_length); | 168 memcpy(insert_at, nalu_ptr, segment_length); |
| 169 insert_at += segment_length; | 169 insert_at += segment_length; |
| 170 nalu_ptr += segment_length; | 170 nalu_ptr += segment_length; |
| 171 } | 171 } |
| 172 } else { | 172 } else { |
| 173 if (video_header.isFirstPacket) { | 173 if (video_header.is_first_packet_in_frame) { |
| 174 memcpy(insert_at, start_code_h264, sizeof(start_code_h264)); | 174 memcpy(insert_at, start_code_h264, sizeof(start_code_h264)); |
| 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 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 205 pps_info.size = pps.size(); | 205 pps_info.size = pps.size(); |
| 206 pps_info.sps_id = parsed_pps->sps_id; | 206 pps_info.sps_id = parsed_pps->sps_id; |
| 207 uint8_t* pps_data = new uint8_t[pps_info.size]; | 207 uint8_t* pps_data = new uint8_t[pps_info.size]; |
| 208 memcpy(pps_data, pps.data(), pps_info.size); | 208 memcpy(pps_data, pps.data(), pps_info.size); |
| 209 pps_info.data.reset(pps_data); | 209 pps_info.data.reset(pps_data); |
| 210 pps_data_[parsed_pps->id] = std::move(pps_info); | 210 pps_data_[parsed_pps->id] = std::move(pps_info); |
| 211 } | 211 } |
| 212 | 212 |
| 213 } // namespace video_coding | 213 } // namespace video_coding |
| 214 } // namespace webrtc | 214 } // namespace webrtc |
| OLD | NEW |