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

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

Issue 1979443004: Add H264 bitstream rewriting to limit frame reordering marker in header (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Addressed comments Created 4 years, 6 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/pps_parser.h ('k') | webrtc/common_video/h264/pps_parser_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/common_video/h264/pps_parser.h"
12
13 #include "webrtc/common_video/h264/h264_common.h"
14 #include "webrtc/base/bitbuffer.h"
15 #include "webrtc/base/buffer.h"
16 #include "webrtc/base/logging.h"
17
18 #define RETURN_EMPTY_ON_FAIL(x) \
19 if (!(x)) { \
20 return rtc::Optional<PpsParser::PpsState>(); \
21 }
22
23 namespace webrtc {
24
25 // General note: this is based off the 02/2014 version of the H.264 standard.
26 // You can find it on this page:
27 // http://www.itu.int/rec/T-REC-H.264
28
29 rtc::Optional<PpsParser::PpsState> PpsParser::ParsePps(const uint8_t* data,
30 size_t length) {
31 // First, parse out rbsp, which is basically the source buffer minus emulation
32 // bytes (the last byte of a 0x00 0x00 0x03 sequence). RBSP is defined in
33 // section 7.3.1 of the H.264 standard.
34 std::unique_ptr<rtc::Buffer> unpacked_buffer = H264::ParseRbsp(data, length);
35 rtc::BitBuffer bit_buffer(unpacked_buffer->data(), unpacked_buffer->size());
36 return ParseInternal(&bit_buffer);
37 }
38
39 rtc::Optional<PpsParser::PpsState> PpsParser::ParseInternal(
40 rtc::BitBuffer* bit_buffer) {
41 PpsState pps;
42
43 uint32_t bits_tmp;
44 uint32_t golomb_ignored;
45 // pic_parameter_set_id: ue(v)
46 RETURN_EMPTY_ON_FAIL(bit_buffer->ReadExponentialGolomb(&golomb_ignored));
47 // seq_parameter_set_id: ue(v)
48 RETURN_EMPTY_ON_FAIL(bit_buffer->ReadExponentialGolomb(&golomb_ignored));
49 // entropy_coding_mode_flag: u(1)
50 uint32_t entropy_coding_mode_flag;
51 RETURN_EMPTY_ON_FAIL(bit_buffer->ReadBits(&entropy_coding_mode_flag, 1));
52 // TODO(pbos): Implement CABAC support if spotted in the wild.
53 RTC_CHECK(entropy_coding_mode_flag == 0)
54 << "Don't know how to parse CABAC streams.";
55 // bottom_field_pic_order_in_frame_present_flag: u(1)
56 uint32_t bottom_field_pic_order_in_frame_present_flag;
57 RETURN_EMPTY_ON_FAIL(
58 bit_buffer->ReadBits(&bottom_field_pic_order_in_frame_present_flag, 1));
59 pps.bottom_field_pic_order_in_frame_present_flag =
60 bottom_field_pic_order_in_frame_present_flag != 0;
61
62 // num_slice_groups_minus1: ue(v)
63 uint32_t num_slice_groups_minus1;
64 RETURN_EMPTY_ON_FAIL(
65 bit_buffer->ReadExponentialGolomb(&num_slice_groups_minus1));
66 if (num_slice_groups_minus1 > 0) {
67 uint32_t slice_group_map_type;
68 // slice_group_map_type: ue(v)
69 RETURN_EMPTY_ON_FAIL(
70 bit_buffer->ReadExponentialGolomb(&slice_group_map_type));
71 if (slice_group_map_type == 0) {
72 for (uint32_t i_group = 0; i_group <= num_slice_groups_minus1;
73 ++i_group) {
74 // run_length_minus1[iGroup]: ue(v)
75 RETURN_EMPTY_ON_FAIL(
76 bit_buffer->ReadExponentialGolomb(&golomb_ignored));
77 }
78 } else if (slice_group_map_type == 1) {
79 // TODO(sprang): Implement support for dispersed slice group map type.
80 // See 8.2.2.2 Specification for dispersed slice group map type.
81 } else if (slice_group_map_type == 2) {
82 for (uint32_t i_group = 0; i_group <= num_slice_groups_minus1;
83 ++i_group) {
84 // top_left[iGroup]: ue(v)
85 RETURN_EMPTY_ON_FAIL(
86 bit_buffer->ReadExponentialGolomb(&golomb_ignored));
87 // bottom_right[iGroup]: ue(v)
88 RETURN_EMPTY_ON_FAIL(
89 bit_buffer->ReadExponentialGolomb(&golomb_ignored));
90 }
91 } else if (slice_group_map_type == 3 || slice_group_map_type == 4 ||
92 slice_group_map_type == 5) {
93 // slice_group_change_direction_flag: u(1)
94 RETURN_EMPTY_ON_FAIL(bit_buffer->ReadBits(&bits_tmp, 1));
95 // slice_group_change_rate_minus1: ue(v)
96 RETURN_EMPTY_ON_FAIL(bit_buffer->ReadExponentialGolomb(&golomb_ignored));
97 } else if (slice_group_map_type == 6) {
98 // pic_size_in_map_units_minus1: ue(v)
99 uint32_t pic_size_in_map_units_minus1;
100 RETURN_EMPTY_ON_FAIL(
101 bit_buffer->ReadExponentialGolomb(&pic_size_in_map_units_minus1));
102 uint32_t slice_group_id_bits = 0;
103 uint32_t num_slice_groups = num_slice_groups_minus1 + 1;
104 // If num_slice_groups is not a power of two an additional bit is required
105 // to account for the ceil() of log2() below.
106 if ((num_slice_groups & (num_slice_groups - 1)) != 0)
107 ++slice_group_id_bits;
108 while (num_slice_groups > 0) {
109 num_slice_groups >>= 1;
110 ++slice_group_id_bits;
111 }
112 for (uint32_t i = 0; i <= pic_size_in_map_units_minus1; i++) {
113 // slice_group_id[i]: u(v)
114 // Represented by ceil(log2(num_slice_groups_minus1 + 1)) bits.
115 RETURN_EMPTY_ON_FAIL(
116 bit_buffer->ReadBits(&bits_tmp, slice_group_id_bits));
117 }
118 }
119 }
120 // num_ref_idx_l0_default_active_minus1: ue(v)
121 RETURN_EMPTY_ON_FAIL(bit_buffer->ReadExponentialGolomb(&golomb_ignored));
122 // num_ref_idx_l1_default_active_minus1: ue(v)
123 RETURN_EMPTY_ON_FAIL(bit_buffer->ReadExponentialGolomb(&golomb_ignored));
124 // weighted_pred_flag: u(1)
125 uint32_t weighted_pred_flag;
126 RETURN_EMPTY_ON_FAIL(bit_buffer->ReadBits(&weighted_pred_flag, 1));
127 pps.weighted_pred_flag = weighted_pred_flag != 0;
128 // weighted_bipred_idc: u(2)
129 RETURN_EMPTY_ON_FAIL(bit_buffer->ReadBits(&pps.weighted_bipred_idc, 2));
130
131 // pic_init_qp_minus26: se(v)
132 RETURN_EMPTY_ON_FAIL(
133 bit_buffer->ReadSignedExponentialGolomb(&pps.pic_init_qp_minus26));
134 // pic_init_qs_minus26: se(v)
135 RETURN_EMPTY_ON_FAIL(bit_buffer->ReadExponentialGolomb(&golomb_ignored));
136 // chroma_qp_index_offset: se(v)
137 RETURN_EMPTY_ON_FAIL(bit_buffer->ReadExponentialGolomb(&golomb_ignored));
138 // deblocking_filter_control_present_flag: u(1)
139 // constrained_intra_pred_flag: u(1)
140 RETURN_EMPTY_ON_FAIL(bit_buffer->ReadBits(&bits_tmp, 2));
141 // redundant_pic_cnt_present_flag: u(1)
142 RETURN_EMPTY_ON_FAIL(
143 bit_buffer->ReadBits(&pps.redundant_pic_cnt_present_flag, 1));
144
145 return rtc::Optional<PpsParser::PpsState>(pps);
146 }
147
148 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/common_video/h264/pps_parser.h ('k') | webrtc/common_video/h264/pps_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698