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

Side by Side Diff: webrtc/common_video/h264/pps_parser.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/h264_common.cc ('k') | webrtc/common_video/h264/sps_parser.cc » ('j') | 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 #include "webrtc/common_video/h264/pps_parser.h" 11 #include "webrtc/common_video/h264/pps_parser.h"
12 12
13 #include <memory> 13 #include <memory>
14 #include <vector>
14 15
15 #include "webrtc/common_video/h264/h264_common.h" 16 #include "webrtc/common_video/h264/h264_common.h"
16 #include "webrtc/base/bitbuffer.h" 17 #include "webrtc/base/bitbuffer.h"
17 #include "webrtc/base/buffer.h"
18 #include "webrtc/base/logging.h" 18 #include "webrtc/base/logging.h"
19 19
20 #define RETURN_EMPTY_ON_FAIL(x) \ 20 #define RETURN_EMPTY_ON_FAIL(x) \
21 if (!(x)) { \ 21 if (!(x)) { \
22 return rtc::Optional<PpsParser::PpsState>(); \ 22 return rtc::Optional<PpsParser::PpsState>(); \
23 } 23 }
24 24
25 namespace { 25 namespace {
26 const int kMaxPicInitQpDeltaValue = 25; 26 const int kMaxPicInitQpDeltaValue = 25;
27 const int kMinPicInitQpDeltaValue = -26; 27 const int kMinPicInitQpDeltaValue = -26;
28 } 28 }
29 29
30 namespace webrtc { 30 namespace webrtc {
31 31
32 // General note: this is based off the 02/2014 version of the H.264 standard. 32 // General note: this is based off the 02/2014 version of the H.264 standard.
33 // You can find it on this page: 33 // You can find it on this page:
34 // http://www.itu.int/rec/T-REC-H.264 34 // http://www.itu.int/rec/T-REC-H.264
35 35
36 rtc::Optional<PpsParser::PpsState> PpsParser::ParsePps(const uint8_t* data, 36 rtc::Optional<PpsParser::PpsState> PpsParser::ParsePps(const uint8_t* data,
37 size_t length) { 37 size_t length) {
38 // First, parse out rbsp, which is basically the source buffer minus emulation 38 // First, parse out rbsp, which is basically the source buffer minus emulation
39 // bytes (the last byte of a 0x00 0x00 0x03 sequence). RBSP is defined in 39 // bytes (the last byte of a 0x00 0x00 0x03 sequence). RBSP is defined in
40 // section 7.3.1 of the H.264 standard. 40 // section 7.3.1 of the H.264 standard.
41 std::unique_ptr<rtc::Buffer> unpacked_buffer = H264::ParseRbsp(data, length); 41 std::vector<uint8_t> unpacked_buffer = H264::ParseRbsp(data, length);
42 rtc::BitBuffer bit_buffer(unpacked_buffer->data(), unpacked_buffer->size()); 42 rtc::BitBuffer bit_buffer(unpacked_buffer.data(), unpacked_buffer.size());
43 return ParseInternal(&bit_buffer); 43 return ParseInternal(&bit_buffer);
44 } 44 }
45 45
46 bool PpsParser::ParsePpsIds(const uint8_t* data, 46 bool PpsParser::ParsePpsIds(const uint8_t* data,
47 size_t length, 47 size_t length,
48 uint32_t* pps_id, 48 uint32_t* pps_id,
49 uint32_t* sps_id) { 49 uint32_t* sps_id) {
50 RTC_DCHECK(pps_id); 50 RTC_DCHECK(pps_id);
51 RTC_DCHECK(sps_id); 51 RTC_DCHECK(sps_id);
52 // First, parse out rbsp, which is basically the source buffer minus emulation 52 // First, parse out rbsp, which is basically the source buffer minus emulation
53 // bytes (the last byte of a 0x00 0x00 0x03 sequence). RBSP is defined in 53 // bytes (the last byte of a 0x00 0x00 0x03 sequence). RBSP is defined in
54 // section 7.3.1 of the H.264 standard. 54 // section 7.3.1 of the H.264 standard.
55 std::unique_ptr<rtc::Buffer> unpacked_buffer = H264::ParseRbsp(data, length); 55 std::vector<uint8_t> unpacked_buffer = H264::ParseRbsp(data, length);
56 rtc::BitBuffer bit_buffer(unpacked_buffer->data(), unpacked_buffer->size()); 56 rtc::BitBuffer bit_buffer(unpacked_buffer.data(), unpacked_buffer.size());
57 return ParsePpsIdsInternal(&bit_buffer, pps_id, sps_id); 57 return ParsePpsIdsInternal(&bit_buffer, pps_id, sps_id);
58 } 58 }
59 59
60 rtc::Optional<uint32_t> PpsParser::ParsePpsIdFromSlice(const uint8_t* data, 60 rtc::Optional<uint32_t> PpsParser::ParsePpsIdFromSlice(const uint8_t* data,
61 size_t length) { 61 size_t length) {
62 std::unique_ptr<rtc::Buffer> slice_rbsp(H264::ParseRbsp(data, length)); 62 std::vector<uint8_t> unpacked_buffer = H264::ParseRbsp(data, length);
63 rtc::BitBuffer slice_reader(slice_rbsp->data(), slice_rbsp->size()); 63 rtc::BitBuffer slice_reader(unpacked_buffer.data(), unpacked_buffer.size());
64 64
65 uint32_t golomb_tmp; 65 uint32_t golomb_tmp;
66 // first_mb_in_slice: ue(v) 66 // first_mb_in_slice: ue(v)
67 if (!slice_reader.ReadExponentialGolomb(&golomb_tmp)) 67 if (!slice_reader.ReadExponentialGolomb(&golomb_tmp))
68 return rtc::Optional<uint32_t>(); 68 return rtc::Optional<uint32_t>();
69 // slice_type: ue(v) 69 // slice_type: ue(v)
70 if (!slice_reader.ReadExponentialGolomb(&golomb_tmp)) 70 if (!slice_reader.ReadExponentialGolomb(&golomb_tmp))
71 return rtc::Optional<uint32_t>(); 71 return rtc::Optional<uint32_t>();
72 // pic_parameter_set_id: ue(v) 72 // pic_parameter_set_id: ue(v)
73 uint32_t slice_pps_id; 73 uint32_t slice_pps_id;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 // pic_parameter_set_id: ue(v) 192 // pic_parameter_set_id: ue(v)
193 if (!bit_buffer->ReadExponentialGolomb(pps_id)) 193 if (!bit_buffer->ReadExponentialGolomb(pps_id))
194 return false; 194 return false;
195 // seq_parameter_set_id: ue(v) 195 // seq_parameter_set_id: ue(v)
196 if (!bit_buffer->ReadExponentialGolomb(sps_id)) 196 if (!bit_buffer->ReadExponentialGolomb(sps_id))
197 return false; 197 return false;
198 return true; 198 return true;
199 } 199 }
200 200
201 } // namespace webrtc 201 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/common_video/h264/h264_common.cc ('k') | webrtc/common_video/h264/sps_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698