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

Side by Side Diff: webrtc/modules/rtp_rtcp/source/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: Fixed compiler warning on win Created 4 years, 7 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
(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/modules/rtp_rtcp/source/h264/pps_parser.h"
12
13 #include "webrtc/modules/rtp_rtcp/source/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_FALSE_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 =
35 H264Common::ParseRbsp(data, length);
36 rtc::BitBuffer bit_buffer(unpacked_buffer->data(), unpacked_buffer->size());
37 return ParseInternal(&bit_buffer);
38 }
39
40 rtc::Optional<PpsParser::PpsState> PpsParser::ParseInternal(
41 rtc::BitBuffer* bit_buffer) {
42 PpsState pps;
43
44 uint32_t bits_tmp;
45 uint32_t golomb_ignored;
46 // pic_parameter_set_id: ue(v)
47 RETURN_FALSE_ON_FAIL(bit_buffer->ReadExponentialGolomb(&golomb_ignored));
48 // seq_parameter_set_id: ue(v)
49 RETURN_FALSE_ON_FAIL(bit_buffer->ReadExponentialGolomb(&golomb_ignored));
50 // entropy_coding_mode_flag: u(1)
51 uint32_t entropy_coding_mode_flag;
52 RETURN_FALSE_ON_FAIL(bit_buffer->ReadBits(&entropy_coding_mode_flag, 1));
53 // TODO(pbos): Implement CABAC support if spotted in the wild.
54 RTC_CHECK(entropy_coding_mode_flag == 0)
55 << "Don't know how to parse CABAC streams.";
56 // bottom_field_pic_order_in_frame_present_flag: u(1)
57 uint32_t bottom_field_pic_order_in_frame_present_flag;
58 RETURN_FALSE_ON_FAIL(
59 bit_buffer->ReadBits(&bottom_field_pic_order_in_frame_present_flag, 1));
60 pps.bottom_field_pic_order_in_frame_present_flag =
61 bottom_field_pic_order_in_frame_present_flag != 0;
62
63 // num_slice_groups_minus1: ue(v)
64 uint32_t num_slice_groups_minus1;
65 RETURN_FALSE_ON_FAIL(
66 bit_buffer->ReadExponentialGolomb(&num_slice_groups_minus1));
67 if (num_slice_groups_minus1 > 0) {
68 uint32_t slice_group_map_type;
69 // slice_group_map_type: ue(v)
70 RETURN_FALSE_ON_FAIL(
71 bit_buffer->ReadExponentialGolomb(&slice_group_map_type));
72 if (slice_group_map_type == 0) {
73 for (uint32_t i_group = 0; i_group <= num_slice_groups_minus1;
74 ++i_group) {
75 // run_length_minus1[iGroup]: ue(v)
76 RETURN_FALSE_ON_FAIL(
77 bit_buffer->ReadExponentialGolomb(&golomb_ignored));
78 }
79 } else if (slice_group_map_type == 2) {
80 for (uint32_t i_group = 0; i_group <= num_slice_groups_minus1;
81 ++i_group) {
82 // top_left[iGroup]: ue(v)
83 RETURN_FALSE_ON_FAIL(
84 bit_buffer->ReadExponentialGolomb(&golomb_ignored));
85 // bottom_right[iGroup]: ue(v)
86 RETURN_FALSE_ON_FAIL(
87 bit_buffer->ReadExponentialGolomb(&golomb_ignored));
88 }
89 } else if (slice_group_map_type == 3 || slice_group_map_type == 4 ||
90 slice_group_map_type == 5) {
91 // slice_group_change_direction_flag: u(1)
92 RETURN_FALSE_ON_FAIL(bit_buffer->ReadBits(&bits_tmp, 1));
93 // slice_group_change_rate_minus1: ue(v)
94 RETURN_FALSE_ON_FAIL(bit_buffer->ReadExponentialGolomb(&golomb_ignored));
95 } else if (slice_group_map_type == 6) {
96 // pic_size_in_map_units_minus1: ue(v)
97 uint32_t pic_size_in_map_units_minus1;
98 RETURN_FALSE_ON_FAIL(
99 bit_buffer->ReadExponentialGolomb(&pic_size_in_map_units_minus1));
100 uint32_t slice_group_id_bits = 0;
101 uint32_t num_slice_groups = num_slice_groups_minus1 + 1;
102 // If num_slice_groups is not a power of two an additional bit is required
103 // to account for the ceil() of log2() below.
104 if ((num_slice_groups & (num_slice_groups - 1)) != 0)
105 ++slice_group_id_bits;
106 while (num_slice_groups > 0) {
107 num_slice_groups >>= 1;
108 ++slice_group_id_bits;
109 }
110 for (uint32_t i = 0; i <= pic_size_in_map_units_minus1; i++) {
111 // slice_group_id[i]: u(v)
112 // Represented by ceil(log2(num_slice_groups_minus1 + 1)) bits.
113 RETURN_FALSE_ON_FAIL(
114 bit_buffer->ReadBits(&bits_tmp, slice_group_id_bits));
115 }
116 }
117 }
118 // num_ref_idx_l0_default_active_minus1: ue(v)
119 RETURN_FALSE_ON_FAIL(bit_buffer->ReadExponentialGolomb(&golomb_ignored));
120 // num_ref_idx_l1_default_active_minus1: ue(v)
121 RETURN_FALSE_ON_FAIL(bit_buffer->ReadExponentialGolomb(&golomb_ignored));
122 // weighted_pred_flag: u(1)
123 uint32_t weighted_pred_flag;
124 RETURN_FALSE_ON_FAIL(bit_buffer->ReadBits(&weighted_pred_flag, 1));
125 pps.weighted_pred_flag = weighted_pred_flag != 0;
126 // weighted_bipred_idc: u(2)
127 RETURN_FALSE_ON_FAIL(bit_buffer->ReadBits(&pps.weighted_bipred_idc, 2));
128
129 // pic_init_qp_minus26: se(v)
130 RETURN_FALSE_ON_FAIL(
131 bit_buffer->ReadSignedExponentialGolomb(&pps.pic_init_qp_minus26));
132 // pic_init_qs_minus26: se(v)
133 RETURN_FALSE_ON_FAIL(bit_buffer->ReadExponentialGolomb(&golomb_ignored));
134 // chroma_qp_index_offset: se(v)
135 RETURN_FALSE_ON_FAIL(bit_buffer->ReadExponentialGolomb(&golomb_ignored));
136 // deblocking_filter_control_present_flag: u(1)
137 // constrained_intra_pred_flag: u(1)
138 RETURN_FALSE_ON_FAIL(bit_buffer->ReadBits(&bits_tmp, 2));
139 // redundant_pic_cnt_present_flag: u(1)
140 RETURN_FALSE_ON_FAIL(
141 bit_buffer->ReadBits(&pps.redundant_pic_cnt_present_flag, 1));
142
143 return rtc::Optional<PpsParser::PpsState>(pps);
144 }
145
146 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698