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

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

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

Powered by Google App Engine
This is Rietveld 408576698