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