Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: webrtc/common_video/h264/sps_vui_rewriter.cc

Issue 2728093002: Optimize ParseRbsp method in H264 bitstream parser. (Closed)
Patch Set: Remove unused includes Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/common_video/h264/sps_parser.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 */
11 11
12 #include "webrtc/common_video/h264/sps_vui_rewriter.h" 12 #include "webrtc/common_video/h264/sps_vui_rewriter.h"
13 13
14 #include <algorithm> 14 #include <algorithm>
15 #include <memory> 15 #include <memory>
16 #include <vector>
16 17
17 #include "webrtc/base/bitbuffer.h" 18 #include "webrtc/base/bitbuffer.h"
18 #include "webrtc/base/checks.h" 19 #include "webrtc/base/checks.h"
19 #include "webrtc/base/logging.h" 20 #include "webrtc/base/logging.h"
20 21
21 #include "webrtc/common_video/h264/h264_common.h" 22 #include "webrtc/common_video/h264/h264_common.h"
22 #include "webrtc/common_video/h264/sps_parser.h" 23 #include "webrtc/common_video/h264/sps_parser.h"
23 24
24 namespace webrtc { 25 namespace webrtc {
25 26
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 bool CopyRemainingBits(rtc::BitBuffer* source, 68 bool CopyRemainingBits(rtc::BitBuffer* source,
68 rtc::BitBufferWriter* destination); 69 rtc::BitBufferWriter* destination);
69 70
70 SpsVuiRewriter::ParseResult SpsVuiRewriter::ParseAndRewriteSps( 71 SpsVuiRewriter::ParseResult SpsVuiRewriter::ParseAndRewriteSps(
71 const uint8_t* buffer, 72 const uint8_t* buffer,
72 size_t length, 73 size_t length,
73 rtc::Optional<SpsParser::SpsState>* sps, 74 rtc::Optional<SpsParser::SpsState>* sps,
74 rtc::Buffer* destination) { 75 rtc::Buffer* destination) {
75 // Create temporary RBSP decoded buffer of the payload (exlcuding the 76 // Create temporary RBSP decoded buffer of the payload (exlcuding the
76 // leading nalu type header byte (the SpsParser uses only the payload). 77 // leading nalu type header byte (the SpsParser uses only the payload).
77 std::unique_ptr<rtc::Buffer> rbsp_buffer = H264::ParseRbsp(buffer, length); 78 std::vector<uint8_t> rbsp_buffer = H264::ParseRbsp(buffer, length);
78 rtc::BitBuffer source_buffer(rbsp_buffer->data(), rbsp_buffer->size()); 79 rtc::BitBuffer source_buffer(rbsp_buffer.data(), rbsp_buffer.size());
79 rtc::Optional<SpsParser::SpsState> sps_state = 80 rtc::Optional<SpsParser::SpsState> sps_state =
80 SpsParser::ParseSpsUpToVui(&source_buffer); 81 SpsParser::ParseSpsUpToVui(&source_buffer);
81 if (!sps_state) 82 if (!sps_state)
82 return ParseResult::kFailure; 83 return ParseResult::kFailure;
83 84
84 *sps = sps_state; 85 *sps = sps_state;
85 86
86 if (sps_state->pic_order_cnt_type >= 2) { 87 if (sps_state->pic_order_cnt_type >= 2) {
87 // No need to rewrite VUI in this case. 88 // No need to rewrite VUI in this case.
88 return ParseResult::kPocOk; 89 return ParseResult::kPocOk;
89 } 90 }
90 91
91 // We're going to completely muck up alignment, so we need a BitBuffer to 92 // We're going to completely muck up alignment, so we need a BitBuffer to
92 // write with. 93 // write with.
93 rtc::Buffer out_buffer(length + kMaxVuiSpsIncrease); 94 rtc::Buffer out_buffer(length + kMaxVuiSpsIncrease);
94 rtc::BitBufferWriter sps_writer(out_buffer.data(), out_buffer.size()); 95 rtc::BitBufferWriter sps_writer(out_buffer.data(), out_buffer.size());
95 96
96 // Check how far the SpsParser has read, and copy that data in bulk. 97 // Check how far the SpsParser has read, and copy that data in bulk.
97 size_t byte_offset; 98 size_t byte_offset;
98 size_t bit_offset; 99 size_t bit_offset;
99 source_buffer.GetCurrentOffset(&byte_offset, &bit_offset); 100 source_buffer.GetCurrentOffset(&byte_offset, &bit_offset);
100 memcpy(out_buffer.data(), rbsp_buffer->data(), 101 memcpy(out_buffer.data(), rbsp_buffer.data(),
101 byte_offset + (bit_offset > 0 ? 1 : 0)); // OK to copy the last bits. 102 byte_offset + (bit_offset > 0 ? 1 : 0)); // OK to copy the last bits.
102 103
103 // SpsParser will have read the vui_params_present flag, which we want to 104 // SpsParser will have read the vui_params_present flag, which we want to
104 // modify, so back off a bit; 105 // modify, so back off a bit;
105 if (bit_offset == 0) { 106 if (bit_offset == 0) {
106 --byte_offset; 107 --byte_offset;
107 bit_offset = 7; 108 bit_offset = 7;
108 } else { 109 } else {
109 --bit_offset; 110 --bit_offset;
110 } 111 }
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 size_t count = std::min(static_cast<size_t>(32u), 354 size_t count = std::min(static_cast<size_t>(32u),
354 static_cast<size_t>(source->RemainingBitCount())); 355 static_cast<size_t>(source->RemainingBitCount()));
355 COPY_BITS(source, destination, bits_tmp, count); 356 COPY_BITS(source, destination, bits_tmp, count);
356 } 357 }
357 // TODO(noahric): The last byte could be all zeroes now, which we should just 358 // TODO(noahric): The last byte could be all zeroes now, which we should just
358 // strip. 359 // strip.
359 return true; 360 return true;
360 } 361 }
361 362
362 } // namespace webrtc 363 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/common_video/h264/sps_parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698