OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 15 matching lines...) Expand all Loading... |
26 using H264::NaluType; | 26 using H264::NaluType; |
27 using H264::ParseNaluType; | 27 using H264::ParseNaluType; |
28 | 28 |
29 const char kAnnexBHeaderBytes[4] = {0, 0, 0, 1}; | 29 const char kAnnexBHeaderBytes[4] = {0, 0, 0, 1}; |
30 const size_t kAvccHeaderByteSize = sizeof(uint32_t); | 30 const size_t kAvccHeaderByteSize = sizeof(uint32_t); |
31 | 31 |
32 bool H264CMSampleBufferToAnnexBBuffer( | 32 bool H264CMSampleBufferToAnnexBBuffer( |
33 CMSampleBufferRef avcc_sample_buffer, | 33 CMSampleBufferRef avcc_sample_buffer, |
34 bool is_keyframe, | 34 bool is_keyframe, |
35 rtc::Buffer* annexb_buffer, | 35 rtc::Buffer* annexb_buffer, |
36 webrtc::RTPFragmentationHeader** out_header) { | 36 std::unique_ptr<RTPFragmentationHeader> *out_header) { |
37 RTC_DCHECK(avcc_sample_buffer); | 37 RTC_DCHECK(avcc_sample_buffer); |
38 RTC_DCHECK(out_header); | 38 RTC_DCHECK(out_header); |
39 *out_header = nullptr; | 39 out_header->reset(nullptr); |
40 | 40 |
41 // Get format description from the sample buffer. | 41 // Get format description from the sample buffer. |
42 CMVideoFormatDescriptionRef description = | 42 CMVideoFormatDescriptionRef description = |
43 CMSampleBufferGetFormatDescription(avcc_sample_buffer); | 43 CMSampleBufferGetFormatDescription(avcc_sample_buffer); |
44 if (description == nullptr) { | 44 if (description == nullptr) { |
45 LOG(LS_ERROR) << "Failed to get sample buffer's description."; | 45 LOG(LS_ERROR) << "Failed to get sample buffer's description."; |
46 return false; | 46 return false; |
47 } | 47 } |
48 | 48 |
49 // Get parameter set information. | 49 // Get parameter set information. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 frag_offsets.push_back(nalu_offset + sizeof(kAnnexBHeaderBytes)); | 136 frag_offsets.push_back(nalu_offset + sizeof(kAnnexBHeaderBytes)); |
137 frag_lengths.push_back(packet_size); | 137 frag_lengths.push_back(packet_size); |
138 nalu_offset += sizeof(kAnnexBHeaderBytes) + packet_size; | 138 nalu_offset += sizeof(kAnnexBHeaderBytes) + packet_size; |
139 | 139 |
140 size_t bytes_written = packet_size + sizeof(kAnnexBHeaderBytes); | 140 size_t bytes_written = packet_size + sizeof(kAnnexBHeaderBytes); |
141 bytes_remaining -= bytes_written; | 141 bytes_remaining -= bytes_written; |
142 data_ptr += bytes_written; | 142 data_ptr += bytes_written; |
143 } | 143 } |
144 RTC_DCHECK_EQ(bytes_remaining, (size_t)0); | 144 RTC_DCHECK_EQ(bytes_remaining, (size_t)0); |
145 | 145 |
146 std::unique_ptr<webrtc::RTPFragmentationHeader> header; | 146 std::unique_ptr<RTPFragmentationHeader> header(new RTPFragmentationHeader()); |
147 header.reset(new webrtc::RTPFragmentationHeader()); | |
148 header->VerifyAndAllocateFragmentationHeader(frag_offsets.size()); | 147 header->VerifyAndAllocateFragmentationHeader(frag_offsets.size()); |
149 RTC_DCHECK_EQ(frag_lengths.size(), frag_offsets.size()); | 148 RTC_DCHECK_EQ(frag_lengths.size(), frag_offsets.size()); |
150 for (size_t i = 0; i < frag_offsets.size(); ++i) { | 149 for (size_t i = 0; i < frag_offsets.size(); ++i) { |
151 header->fragmentationOffset[i] = frag_offsets[i]; | 150 header->fragmentationOffset[i] = frag_offsets[i]; |
152 header->fragmentationLength[i] = frag_lengths[i]; | 151 header->fragmentationLength[i] = frag_lengths[i]; |
153 header->fragmentationPlType[i] = 0; | 152 header->fragmentationPlType[i] = 0; |
154 header->fragmentationTimeDiff[i] = 0; | 153 header->fragmentationTimeDiff[i] = 0; |
155 } | 154 } |
156 *out_header = header.release(); | 155 *out_header = std::move(header); |
157 CFRelease(contiguous_buffer); | 156 CFRelease(contiguous_buffer); |
158 return true; | 157 return true; |
159 } | 158 } |
160 | 159 |
161 bool H264AnnexBBufferToCMSampleBuffer(const uint8_t* annexb_buffer, | 160 bool H264AnnexBBufferToCMSampleBuffer(const uint8_t* annexb_buffer, |
162 size_t annexb_buffer_size, | 161 size_t annexb_buffer_size, |
163 CMVideoFormatDescriptionRef video_format, | 162 CMVideoFormatDescriptionRef video_format, |
164 CMSampleBufferRef* out_sample_buffer) { | 163 CMSampleBufferRef* out_sample_buffer) { |
165 RTC_DCHECK(annexb_buffer); | 164 RTC_DCHECK(annexb_buffer); |
166 RTC_DCHECK(out_sample_buffer); | 165 RTC_DCHECK(out_sample_buffer); |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 memcpy(start_ + offset_, data, data_size); | 355 memcpy(start_ + offset_, data, data_size); |
357 offset_ += data_size; | 356 offset_ += data_size; |
358 return true; | 357 return true; |
359 } | 358 } |
360 | 359 |
361 size_t AvccBufferWriter::BytesRemaining() const { | 360 size_t AvccBufferWriter::BytesRemaining() const { |
362 return length_ - offset_; | 361 return length_ - offset_; |
363 } | 362 } |
364 | 363 |
365 } // namespace webrtc | 364 } // namespace webrtc |
OLD | NEW |