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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 pps_data_[nalu.pps_id].size = nalu.size; | 60 pps_data_[nalu.pps_id].size = nalu.size; |
61 pps_data_[nalu.pps_id].data.reset(new uint8_t[nalu.size]); | 61 pps_data_[nalu.pps_id].data.reset(new uint8_t[nalu.size]); |
62 memcpy(pps_data_[nalu.pps_id].data.get(), data + nalu.offset, | 62 memcpy(pps_data_[nalu.pps_id].data.get(), data + nalu.offset, |
63 nalu.size); | 63 nalu.size); |
64 break; | 64 break; |
65 } | 65 } |
66 case H264::NaluType::kIdr: { | 66 case H264::NaluType::kIdr: { |
67 // If this is the first packet of an IDR, make sure we have the required | 67 // If this is the first packet of an IDR, make sure we have the required |
68 // SPS/PPS and also calculate how much extra space we need in the buffer | 68 // SPS/PPS and also calculate how much extra space we need in the buffer |
69 // to prepend the SPS/PPS to the bitstream with start codes. | 69 // to prepend the SPS/PPS to the bitstream with start codes. |
70 if (video_header.is_first_packet_in_frame) { | 70 if (video_header.isFirstPacket) { |
71 if (nalu.pps_id == -1) { | 71 if (nalu.pps_id == -1) { |
72 LOG(LS_WARNING) << "No PPS id in IDR nalu."; | 72 LOG(LS_WARNING) << "No PPS id in IDR nalu."; |
73 return kRequestKeyframe; | 73 return kRequestKeyframe; |
74 } | 74 } |
75 | 75 |
76 auto pps = pps_data_.find(nalu.pps_id); | 76 auto pps = pps_data_.find(nalu.pps_id); |
77 if (pps == pps_data_.end()) { | 77 if (pps == pps_data_.end()) { |
78 LOG(LS_WARNING) << "No PPS with id << " << nalu.pps_id | 78 LOG(LS_WARNING) << "No PPS with id << " << nalu.pps_id |
79 << " received"; | 79 << " received"; |
80 return kRequestKeyframe; | 80 return kRequestKeyframe; |
(...skipping 20 matching lines...) Expand all Loading... |
101 } | 101 } |
102 } | 102 } |
103 | 103 |
104 if (!insert_packet) | 104 if (!insert_packet) |
105 return kDrop; | 105 return kDrop; |
106 | 106 |
107 // Calculate how much space we need for the rest of the bitstream. | 107 // Calculate how much space we need for the rest of the bitstream. |
108 if (codec_header.packetization_type == kH264StapA) { | 108 if (codec_header.packetization_type == kH264StapA) { |
109 const uint8_t* nalu_ptr = data + 1; | 109 const uint8_t* nalu_ptr = data + 1; |
110 while (nalu_ptr < data + data_size) { | 110 while (nalu_ptr < data + data_size) { |
111 RTC_DCHECK(video_header.is_first_packet_in_frame); | 111 RTC_DCHECK(video_header.isFirstPacket); |
112 required_size += sizeof(start_code_h264); | 112 required_size += sizeof(start_code_h264); |
113 | 113 |
114 // The first two bytes describe the length of a segment. | 114 // The first two bytes describe the length of a segment. |
115 uint16_t segment_length = nalu_ptr[0] << 8 | nalu_ptr[1]; | 115 uint16_t segment_length = nalu_ptr[0] << 8 | nalu_ptr[1]; |
116 nalu_ptr += 2; | 116 nalu_ptr += 2; |
117 | 117 |
118 required_size += segment_length; | 118 required_size += segment_length; |
119 nalu_ptr += segment_length; | 119 nalu_ptr += segment_length; |
120 } | 120 } |
121 } else { | 121 } else { |
122 if (video_header.is_first_packet_in_frame) | 122 if (video_header.isFirstPacket) |
123 required_size += sizeof(start_code_h264); | 123 required_size += sizeof(start_code_h264); |
124 required_size += data_size; | 124 required_size += data_size; |
125 } | 125 } |
126 | 126 |
127 // Then we copy to the new buffer. | 127 // Then we copy to the new buffer. |
128 uint8_t* buffer = new uint8_t[required_size]; | 128 uint8_t* buffer = new uint8_t[required_size]; |
129 uint8_t* insert_at = buffer; | 129 uint8_t* insert_at = buffer; |
130 | 130 |
131 // If pps_id != -1 then we have the SPS/PPS and they should be prepended | 131 // If pps_id != -1 then we have the SPS/PPS and they should be prepended |
132 // to the bitstream with start codes inserted. | 132 // to the bitstream with start codes inserted. |
(...skipping 27 matching lines...) Expand all Loading... |
160 if (copy_end > data_size) { | 160 if (copy_end > data_size) { |
161 delete[] buffer; | 161 delete[] buffer; |
162 return kDrop; | 162 return kDrop; |
163 } | 163 } |
164 | 164 |
165 memcpy(insert_at, nalu_ptr, segment_length); | 165 memcpy(insert_at, nalu_ptr, segment_length); |
166 insert_at += segment_length; | 166 insert_at += segment_length; |
167 nalu_ptr += segment_length; | 167 nalu_ptr += segment_length; |
168 } | 168 } |
169 } else { | 169 } else { |
170 if (video_header.is_first_packet_in_frame) { | 170 if (video_header.isFirstPacket) { |
171 memcpy(insert_at, start_code_h264, sizeof(start_code_h264)); | 171 memcpy(insert_at, start_code_h264, sizeof(start_code_h264)); |
172 insert_at += sizeof(start_code_h264); | 172 insert_at += sizeof(start_code_h264); |
173 } | 173 } |
174 memcpy(insert_at, data, data_size); | 174 memcpy(insert_at, data, data_size); |
175 } | 175 } |
176 | 176 |
177 packet->dataPtr = buffer; | 177 packet->dataPtr = buffer; |
178 packet->sizeBytes = required_size; | 178 packet->sizeBytes = required_size; |
179 return kInsert; | 179 return kInsert; |
180 } | 180 } |
181 | 181 |
182 } // namespace video_coding | 182 } // namespace video_coding |
183 } // namespace webrtc | 183 } // namespace webrtc |
OLD | NEW |