| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 bool AddBitstreamRestriction(rtc::BitBufferWriter* destination, | 65 bool AddBitstreamRestriction(rtc::BitBufferWriter* destination, |
| 66 uint32_t max_num_ref_frames); | 66 uint32_t max_num_ref_frames); |
| 67 bool CopyRemainingBits(rtc::BitBuffer* source, | 67 bool CopyRemainingBits(rtc::BitBuffer* source, |
| 68 rtc::BitBufferWriter* destination); | 68 rtc::BitBufferWriter* destination); |
| 69 | 69 |
| 70 SpsVuiRewriter::ParseResult SpsVuiRewriter::ParseAndRewriteSps( | 70 SpsVuiRewriter::ParseResult SpsVuiRewriter::ParseAndRewriteSps( |
| 71 const uint8_t* buffer, | 71 const uint8_t* buffer, |
| 72 size_t length, | 72 size_t length, |
| 73 rtc::Optional<SpsParser::SpsState>* sps, | 73 rtc::Optional<SpsParser::SpsState>* sps, |
| 74 rtc::Buffer* destination) { | 74 rtc::Buffer* destination) { |
| 75 rtc::BitBuffer source_buffer(buffer, length); | 75 // Create temporary RBSP decoded buffer of the payload (exlcuding the |
| 76 // leading nalu type header byte (the SpsParser uses only the payload). |
| 77 std::unique_ptr<rtc::Buffer> rbsp_buffer = H264::ParseRbsp(buffer, length); |
| 78 rtc::BitBuffer source_buffer(rbsp_buffer->data(), rbsp_buffer->size()); |
| 76 rtc::Optional<SpsParser::SpsState> sps_state = | 79 rtc::Optional<SpsParser::SpsState> sps_state = |
| 77 SpsParser::ParseSpsUpToVui(&source_buffer); | 80 SpsParser::ParseSpsUpToVui(&source_buffer); |
| 78 if (!sps_state) | 81 if (!sps_state) |
| 79 return ParseResult::kFailure; | 82 return ParseResult::kFailure; |
| 80 | 83 |
| 81 *sps = sps_state; | 84 *sps = sps_state; |
| 82 | 85 |
| 83 if (sps_state->pic_order_cnt_type >= 2) { | 86 if (sps_state->pic_order_cnt_type >= 2) { |
| 84 // No need to rewrite VUI in this case. | 87 // No need to rewrite VUI in this case. |
| 85 return ParseResult::kPocOk; | 88 return ParseResult::kPocOk; |
| 86 } | 89 } |
| 87 | 90 |
| 88 // We're going to completely muck up alignment, so we need a BitBuffer to | 91 // We're going to completely muck up alignment, so we need a BitBuffer to |
| 89 // write with. | 92 // write with. |
| 90 rtc::Buffer out_buffer(length + kMaxVuiSpsIncrease); | 93 rtc::Buffer out_buffer(length + kMaxVuiSpsIncrease); |
| 91 rtc::BitBufferWriter sps_writer(out_buffer.data(), out_buffer.size()); | 94 rtc::BitBufferWriter sps_writer(out_buffer.data(), out_buffer.size()); |
| 92 | 95 |
| 93 // Check how far the SpsParser has read, and copy that data in bulk. | 96 // Check how far the SpsParser has read, and copy that data in bulk. |
| 94 size_t byte_offset; | 97 size_t byte_offset; |
| 95 size_t bit_offset; | 98 size_t bit_offset; |
| 96 source_buffer.GetCurrentOffset(&byte_offset, &bit_offset); | 99 source_buffer.GetCurrentOffset(&byte_offset, &bit_offset); |
| 97 memcpy(out_buffer.data(), buffer, | 100 memcpy(out_buffer.data(), rbsp_buffer->data(), |
| 98 byte_offset + (bit_offset > 0 ? 1 : 0)); // OK to copy the last bits. | 101 byte_offset + (bit_offset > 0 ? 1 : 0)); // OK to copy the last bits. |
| 99 | 102 |
| 100 // SpsParser will have read the vui_params_present flag, which we want to | 103 // SpsParser will have read the vui_params_present flag, which we want to |
| 101 // modify, so back off a bit; | 104 // modify, so back off a bit; |
| 102 if (bit_offset == 0) { | 105 if (bit_offset == 0) { |
| 103 --byte_offset; | 106 --byte_offset; |
| 104 bit_offset = 7; | 107 bit_offset = 7; |
| 105 } else { | 108 } else { |
| 106 --bit_offset; | 109 --bit_offset; |
| 107 } | 110 } |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 size_t count = std::min(static_cast<size_t>(32u), | 353 size_t count = std::min(static_cast<size_t>(32u), |
| 351 static_cast<size_t>(source->RemainingBitCount())); | 354 static_cast<size_t>(source->RemainingBitCount())); |
| 352 COPY_BITS(source, destination, bits_tmp, count); | 355 COPY_BITS(source, destination, bits_tmp, count); |
| 353 } | 356 } |
| 354 // TODO(noahric): The last byte could be all zeroes now, which we should just | 357 // TODO(noahric): The last byte could be all zeroes now, which we should just |
| 355 // strip. | 358 // strip. |
| 356 return true; | 359 return true; |
| 357 } | 360 } |
| 358 | 361 |
| 359 } // namespace webrtc | 362 } // namespace webrtc |
| OLD | NEW |