| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 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/modules/rtp_rtcp/source/h264_sps_parser.h" | 11 #include "webrtc/common_video/h264/sps_parser.h" |
| 12 | 12 |
| 13 #include "webrtc/common_video/h264/h264_common.h" |
| 13 #include "webrtc/base/bitbuffer.h" | 14 #include "webrtc/base/bitbuffer.h" |
| 14 #include "webrtc/base/bytebuffer.h" | 15 #include "webrtc/base/bytebuffer.h" |
| 15 #include "webrtc/base/logging.h" | 16 #include "webrtc/base/logging.h" |
| 16 | 17 |
| 17 #define RETURN_FALSE_ON_FAIL(x) \ | 18 typedef rtc::Optional<webrtc::SpsParser::SpsState> OptionalSps; |
| 19 |
| 20 #define RETURN_EMPTY_ON_FAIL(x) \ |
| 18 if (!(x)) { \ | 21 if (!(x)) { \ |
| 19 return false; \ | 22 return OptionalSps(); \ |
| 20 } | 23 } |
| 21 | 24 |
| 22 namespace webrtc { | 25 namespace webrtc { |
| 23 | 26 |
| 24 H264SpsParser::H264SpsParser(const uint8_t* sps, size_t byte_length) | 27 // General note: this is based off the 02/2014 version of the H.264 standard. |
| 25 : sps_(sps), byte_length_(byte_length), width_(), height_() { | 28 // You can find it on this page: |
| 29 // http://www.itu.int/rec/T-REC-H.264 |
| 30 |
| 31 // Unpack RBSP and parse SPS state from the supplied buffer. |
| 32 rtc::Optional<SpsParser::SpsState> SpsParser::ParseSps(const uint8_t* data, |
| 33 size_t length) { |
| 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 ParseSpsUpToVui(&bit_buffer); |
| 26 } | 37 } |
| 27 | 38 |
| 28 bool H264SpsParser::Parse() { | 39 rtc::Optional<SpsParser::SpsState> SpsParser::ParseSpsUpToVui( |
| 29 // General note: this is based off the 02/2014 version of the H.264 standard. | 40 rtc::BitBuffer* buffer) { |
| 30 // You can find it on this page: | |
| 31 // http://www.itu.int/rec/T-REC-H.264 | |
| 32 | |
| 33 const char* sps_bytes = reinterpret_cast<const char*>(sps_); | |
| 34 // First, parse out rbsp, which is basically the source buffer minus emulation | |
| 35 // bytes (the last byte of a 0x00 0x00 0x03 sequence). RBSP is defined in | |
| 36 // section 7.3.1 of the H.264 standard. | |
| 37 rtc::ByteBufferWriter rbsp_buffer; | |
| 38 for (size_t i = 0; i < byte_length_;) { | |
| 39 // Be careful about over/underflow here. byte_length_ - 3 can underflow, and | |
| 40 // i + 3 can overflow, but byte_length_ - i can't, because i < byte_length_ | |
| 41 // above, and that expression will produce the number of bytes left in | |
| 42 // the stream including the byte at i. | |
| 43 if (byte_length_ - i >= 3 && sps_[i] == 0 && sps_[i + 1] == 0 && | |
| 44 sps_[i + 2] == 3) { | |
| 45 // Two rbsp bytes + the emulation byte. | |
| 46 rbsp_buffer.WriteBytes(sps_bytes + i, 2); | |
| 47 i += 3; | |
| 48 } else { | |
| 49 // Single rbsp byte. | |
| 50 rbsp_buffer.WriteBytes(sps_bytes + i, 1); | |
| 51 i++; | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 // Now, we need to use a bit buffer to parse through the actual AVC SPS | 41 // Now, we need to use a bit buffer to parse through the actual AVC SPS |
| 56 // format. See Section 7.3.2.1.1 ("Sequence parameter set data syntax") of the | 42 // format. See Section 7.3.2.1.1 ("Sequence parameter set data syntax") of the |
| 57 // H.264 standard for a complete description. | 43 // H.264 standard for a complete description. |
| 58 // Since we only care about resolution, we ignore the majority of fields, but | 44 // Since we only care about resolution, we ignore the majority of fields, but |
| 59 // we still have to actively parse through a lot of the data, since many of | 45 // we still have to actively parse through a lot of the data, since many of |
| 60 // the fields have variable size. | 46 // the fields have variable size. |
| 61 // We're particularly interested in: | 47 // We're particularly interested in: |
| 62 // chroma_format_idc -> affects crop units | 48 // chroma_format_idc -> affects crop units |
| 63 // pic_{width,height}_* -> resolution of the frame in macroblocks (16x16). | 49 // pic_{width,height}_* -> resolution of the frame in macroblocks (16x16). |
| 64 // frame_crop_*_offset -> crop information | 50 // frame_crop_*_offset -> crop information |
| 65 rtc::BitBuffer parser(reinterpret_cast<const uint8_t*>(rbsp_buffer.Data()), | 51 |
| 66 rbsp_buffer.Length()); | 52 SpsState sps; |
| 67 | 53 |
| 68 // The golomb values we have to read, not just consume. | 54 // The golomb values we have to read, not just consume. |
| 69 uint32_t golomb_ignored; | 55 uint32_t golomb_ignored; |
| 70 | 56 |
| 71 // separate_colour_plane_flag is optional (assumed 0), but has implications | |
| 72 // about the ChromaArrayType, which modifies how we treat crop coordinates. | |
| 73 uint32_t separate_colour_plane_flag = 0; | |
| 74 // chroma_format_idc will be ChromaArrayType if separate_colour_plane_flag is | 57 // chroma_format_idc will be ChromaArrayType if separate_colour_plane_flag is |
| 75 // 0. It defaults to 1, when not specified. | 58 // 0. It defaults to 1, when not specified. |
| 76 uint32_t chroma_format_idc = 1; | 59 uint32_t chroma_format_idc = 1; |
| 77 | 60 |
| 78 // profile_idc: u(8). We need it to determine if we need to read/skip chroma | 61 // profile_idc: u(8). We need it to determine if we need to read/skip chroma |
| 79 // formats. | 62 // formats. |
| 80 uint8_t profile_idc; | 63 uint8_t profile_idc; |
| 81 RETURN_FALSE_ON_FAIL(parser.ReadUInt8(&profile_idc)); | 64 RETURN_EMPTY_ON_FAIL(buffer->ReadUInt8(&profile_idc)); |
| 82 // constraint_set0_flag through constraint_set5_flag + reserved_zero_2bits | 65 // constraint_set0_flag through constraint_set5_flag + reserved_zero_2bits |
| 83 // 1 bit each for the flags + 2 bits = 8 bits = 1 byte. | 66 // 1 bit each for the flags + 2 bits = 8 bits = 1 byte. |
| 84 RETURN_FALSE_ON_FAIL(parser.ConsumeBytes(1)); | 67 RETURN_EMPTY_ON_FAIL(buffer->ConsumeBytes(1)); |
| 85 // level_idc: u(8) | 68 // level_idc: u(8) |
| 86 RETURN_FALSE_ON_FAIL(parser.ConsumeBytes(1)); | 69 RETURN_EMPTY_ON_FAIL(buffer->ConsumeBytes(1)); |
| 87 // seq_parameter_set_id: ue(v) | 70 // seq_parameter_set_id: ue(v) |
| 88 RETURN_FALSE_ON_FAIL(parser.ReadExponentialGolomb(&golomb_ignored)); | 71 RETURN_EMPTY_ON_FAIL(buffer->ReadExponentialGolomb(&golomb_ignored)); |
| 72 sps.separate_colour_plane_flag = 0; |
| 89 // See if profile_idc has chroma format information. | 73 // See if profile_idc has chroma format information. |
| 90 if (profile_idc == 100 || profile_idc == 110 || profile_idc == 122 || | 74 if (profile_idc == 100 || profile_idc == 110 || profile_idc == 122 || |
| 91 profile_idc == 244 || profile_idc == 44 || profile_idc == 83 || | 75 profile_idc == 244 || profile_idc == 44 || profile_idc == 83 || |
| 92 profile_idc == 86 || profile_idc == 118 || profile_idc == 128 || | 76 profile_idc == 86 || profile_idc == 118 || profile_idc == 128 || |
| 93 profile_idc == 138 || profile_idc == 139 || profile_idc == 134) { | 77 profile_idc == 138 || profile_idc == 139 || profile_idc == 134) { |
| 94 // chroma_format_idc: ue(v) | 78 // chroma_format_idc: ue(v) |
| 95 RETURN_FALSE_ON_FAIL(parser.ReadExponentialGolomb(&chroma_format_idc)); | 79 RETURN_EMPTY_ON_FAIL(buffer->ReadExponentialGolomb(&chroma_format_idc)); |
| 96 if (chroma_format_idc == 3) { | 80 if (chroma_format_idc == 3) { |
| 97 // separate_colour_plane_flag: u(1) | 81 // separate_colour_plane_flag: u(1) |
| 98 RETURN_FALSE_ON_FAIL(parser.ReadBits(&separate_colour_plane_flag, 1)); | 82 RETURN_EMPTY_ON_FAIL( |
| 83 buffer->ReadBits(&sps.separate_colour_plane_flag, 1)); |
| 99 } | 84 } |
| 100 // bit_depth_luma_minus8: ue(v) | 85 // bit_depth_luma_minus8: ue(v) |
| 101 RETURN_FALSE_ON_FAIL(parser.ReadExponentialGolomb(&golomb_ignored)); | 86 RETURN_EMPTY_ON_FAIL(buffer->ReadExponentialGolomb(&golomb_ignored)); |
| 102 // bit_depth_chroma_minus8: ue(v) | 87 // bit_depth_chroma_minus8: ue(v) |
| 103 RETURN_FALSE_ON_FAIL(parser.ReadExponentialGolomb(&golomb_ignored)); | 88 RETURN_EMPTY_ON_FAIL(buffer->ReadExponentialGolomb(&golomb_ignored)); |
| 104 // qpprime_y_zero_transform_bypass_flag: u(1) | 89 // qpprime_y_zero_transform_bypass_flag: u(1) |
| 105 RETURN_FALSE_ON_FAIL(parser.ConsumeBits(1)); | 90 RETURN_EMPTY_ON_FAIL(buffer->ConsumeBits(1)); |
| 106 // seq_scaling_matrix_present_flag: u(1) | 91 // seq_scaling_matrix_present_flag: u(1) |
| 107 uint32_t seq_scaling_matrix_present_flag; | 92 uint32_t seq_scaling_matrix_present_flag; |
| 108 RETURN_FALSE_ON_FAIL(parser.ReadBits(&seq_scaling_matrix_present_flag, 1)); | 93 RETURN_EMPTY_ON_FAIL(buffer->ReadBits(&seq_scaling_matrix_present_flag, 1)); |
| 109 if (seq_scaling_matrix_present_flag) { | 94 if (seq_scaling_matrix_present_flag) { |
| 110 // seq_scaling_list_present_flags. Either 8 or 12, depending on | 95 // seq_scaling_list_present_flags. Either 8 or 12, depending on |
| 111 // chroma_format_idc. | 96 // chroma_format_idc. |
| 112 uint32_t seq_scaling_list_present_flags; | 97 uint32_t seq_scaling_list_present_flags; |
| 113 if (chroma_format_idc != 3) { | 98 if (chroma_format_idc != 3) { |
| 114 RETURN_FALSE_ON_FAIL( | 99 RETURN_EMPTY_ON_FAIL( |
| 115 parser.ReadBits(&seq_scaling_list_present_flags, 8)); | 100 buffer->ReadBits(&seq_scaling_list_present_flags, 8)); |
| 116 } else { | 101 } else { |
| 117 RETURN_FALSE_ON_FAIL( | 102 RETURN_EMPTY_ON_FAIL( |
| 118 parser.ReadBits(&seq_scaling_list_present_flags, 12)); | 103 buffer->ReadBits(&seq_scaling_list_present_flags, 12)); |
| 119 } | 104 } |
| 120 // We don't support reading the sequence scaling list, and we don't really | 105 // We don't support reading the sequence scaling list, and we don't really |
| 121 // see/use them in practice, so we'll just reject the full sps if we see | 106 // see/use them in practice, so we'll just reject the full sps if we see |
| 122 // any provided. | 107 // any provided. |
| 123 if (seq_scaling_list_present_flags > 0) { | 108 if (seq_scaling_list_present_flags > 0) { |
| 124 LOG(LS_WARNING) << "SPS contains scaling lists, which are unsupported."; | 109 LOG(LS_WARNING) << "SPS contains scaling lists, which are unsupported."; |
| 125 return false; | 110 return OptionalSps(); |
| 126 } | 111 } |
| 127 } | 112 } |
| 128 } | 113 } |
| 129 // log2_max_frame_num_minus4: ue(v) | 114 // log2_max_frame_num_minus4: ue(v) |
| 130 RETURN_FALSE_ON_FAIL(parser.ReadExponentialGolomb(&golomb_ignored)); | 115 RETURN_EMPTY_ON_FAIL( |
| 116 buffer->ReadExponentialGolomb(&sps.log2_max_frame_num_minus4)); |
| 131 // pic_order_cnt_type: ue(v) | 117 // pic_order_cnt_type: ue(v) |
| 132 uint32_t pic_order_cnt_type; | 118 RETURN_EMPTY_ON_FAIL(buffer->ReadExponentialGolomb(&sps.pic_order_cnt_type)); |
| 133 RETURN_FALSE_ON_FAIL(parser.ReadExponentialGolomb(&pic_order_cnt_type)); | 119 if (sps.pic_order_cnt_type == 0) { |
| 134 if (pic_order_cnt_type == 0) { | |
| 135 // log2_max_pic_order_cnt_lsb_minus4: ue(v) | 120 // log2_max_pic_order_cnt_lsb_minus4: ue(v) |
| 136 RETURN_FALSE_ON_FAIL(parser.ReadExponentialGolomb(&golomb_ignored)); | 121 RETURN_EMPTY_ON_FAIL( |
| 137 } else if (pic_order_cnt_type == 1) { | 122 buffer->ReadExponentialGolomb(&sps.log2_max_pic_order_cnt_lsb_minus4)); |
| 123 } else if (sps.pic_order_cnt_type == 1) { |
| 138 // delta_pic_order_always_zero_flag: u(1) | 124 // delta_pic_order_always_zero_flag: u(1) |
| 139 RETURN_FALSE_ON_FAIL(parser.ConsumeBits(1)); | 125 RETURN_EMPTY_ON_FAIL( |
| 126 buffer->ReadBits(&sps.delta_pic_order_always_zero_flag, 1)); |
| 140 // offset_for_non_ref_pic: se(v) | 127 // offset_for_non_ref_pic: se(v) |
| 141 RETURN_FALSE_ON_FAIL(parser.ReadExponentialGolomb(&golomb_ignored)); | 128 RETURN_EMPTY_ON_FAIL(buffer->ReadExponentialGolomb(&golomb_ignored)); |
| 142 // offset_for_top_to_bottom_field: se(v) | 129 // offset_for_top_to_bottom_field: se(v) |
| 143 RETURN_FALSE_ON_FAIL(parser.ReadExponentialGolomb(&golomb_ignored)); | 130 RETURN_EMPTY_ON_FAIL(buffer->ReadExponentialGolomb(&golomb_ignored)); |
| 144 // num_ref_frames_in_pic_order_cnt_cycle: ue(v) | 131 // num_ref_frames_in_pic_order_cnt_cycle: ue(v) |
| 145 uint32_t num_ref_frames_in_pic_order_cnt_cycle; | 132 uint32_t num_ref_frames_in_pic_order_cnt_cycle; |
| 146 RETURN_FALSE_ON_FAIL( | 133 RETURN_EMPTY_ON_FAIL( |
| 147 parser.ReadExponentialGolomb(&num_ref_frames_in_pic_order_cnt_cycle)); | 134 buffer->ReadExponentialGolomb(&num_ref_frames_in_pic_order_cnt_cycle)); |
| 148 for (size_t i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; ++i) { | 135 for (size_t i = 0; i < num_ref_frames_in_pic_order_cnt_cycle; ++i) { |
| 149 // offset_for_ref_frame[i]: se(v) | 136 // offset_for_ref_frame[i]: se(v) |
| 150 RETURN_FALSE_ON_FAIL(parser.ReadExponentialGolomb(&golomb_ignored)); | 137 RETURN_EMPTY_ON_FAIL(buffer->ReadExponentialGolomb(&golomb_ignored)); |
| 151 } | 138 } |
| 152 } | 139 } |
| 153 // max_num_ref_frames: ue(v) | 140 // max_num_ref_frames: ue(v) |
| 154 RETURN_FALSE_ON_FAIL(parser.ReadExponentialGolomb(&golomb_ignored)); | 141 RETURN_EMPTY_ON_FAIL(buffer->ReadExponentialGolomb(&sps.max_num_ref_frames)); |
| 155 // gaps_in_frame_num_value_allowed_flag: u(1) | 142 // gaps_in_frame_num_value_allowed_flag: u(1) |
| 156 RETURN_FALSE_ON_FAIL(parser.ConsumeBits(1)); | 143 RETURN_EMPTY_ON_FAIL(buffer->ConsumeBits(1)); |
| 157 // | 144 // |
| 158 // IMPORTANT ONES! Now we're getting to resolution. First we read the pic | 145 // IMPORTANT ONES! Now we're getting to resolution. First we read the pic |
| 159 // width/height in macroblocks (16x16), which gives us the base resolution, | 146 // width/height in macroblocks (16x16), which gives us the base resolution, |
| 160 // and then we continue on until we hit the frame crop offsets, which are used | 147 // and then we continue on until we hit the frame crop offsets, which are used |
| 161 // to signify resolutions that aren't multiples of 16. | 148 // to signify resolutions that aren't multiples of 16. |
| 162 // | 149 // |
| 163 // pic_width_in_mbs_minus1: ue(v) | 150 // pic_width_in_mbs_minus1: ue(v) |
| 164 uint32_t pic_width_in_mbs_minus1; | 151 uint32_t pic_width_in_mbs_minus1; |
| 165 RETURN_FALSE_ON_FAIL(parser.ReadExponentialGolomb(&pic_width_in_mbs_minus1)); | 152 RETURN_EMPTY_ON_FAIL(buffer->ReadExponentialGolomb(&pic_width_in_mbs_minus1)); |
| 166 // pic_height_in_map_units_minus1: ue(v) | 153 // pic_height_in_map_units_minus1: ue(v) |
| 167 uint32_t pic_height_in_map_units_minus1; | 154 uint32_t pic_height_in_map_units_minus1; |
| 168 RETURN_FALSE_ON_FAIL( | 155 RETURN_EMPTY_ON_FAIL( |
| 169 parser.ReadExponentialGolomb(&pic_height_in_map_units_minus1)); | 156 buffer->ReadExponentialGolomb(&pic_height_in_map_units_minus1)); |
| 170 // frame_mbs_only_flag: u(1) | 157 // frame_mbs_only_flag: u(1) |
| 171 uint32_t frame_mbs_only_flag; | 158 RETURN_EMPTY_ON_FAIL(buffer->ReadBits(&sps.frame_mbs_only_flag, 1)); |
| 172 RETURN_FALSE_ON_FAIL(parser.ReadBits(&frame_mbs_only_flag, 1)); | 159 if (!sps.frame_mbs_only_flag) { |
| 173 if (!frame_mbs_only_flag) { | |
| 174 // mb_adaptive_frame_field_flag: u(1) | 160 // mb_adaptive_frame_field_flag: u(1) |
| 175 RETURN_FALSE_ON_FAIL(parser.ConsumeBits(1)); | 161 RETURN_EMPTY_ON_FAIL(buffer->ConsumeBits(1)); |
| 176 } | 162 } |
| 177 // direct_8x8_inference_flag: u(1) | 163 // direct_8x8_inference_flag: u(1) |
| 178 RETURN_FALSE_ON_FAIL(parser.ConsumeBits(1)); | 164 RETURN_EMPTY_ON_FAIL(buffer->ConsumeBits(1)); |
| 179 // | 165 // |
| 180 // MORE IMPORTANT ONES! Now we're at the frame crop information. | 166 // MORE IMPORTANT ONES! Now we're at the frame crop information. |
| 181 // | 167 // |
| 182 // frame_cropping_flag: u(1) | 168 // frame_cropping_flag: u(1) |
| 183 uint32_t frame_cropping_flag; | 169 uint32_t frame_cropping_flag; |
| 184 uint32_t frame_crop_left_offset = 0; | 170 uint32_t frame_crop_left_offset = 0; |
| 185 uint32_t frame_crop_right_offset = 0; | 171 uint32_t frame_crop_right_offset = 0; |
| 186 uint32_t frame_crop_top_offset = 0; | 172 uint32_t frame_crop_top_offset = 0; |
| 187 uint32_t frame_crop_bottom_offset = 0; | 173 uint32_t frame_crop_bottom_offset = 0; |
| 188 RETURN_FALSE_ON_FAIL(parser.ReadBits(&frame_cropping_flag, 1)); | 174 RETURN_EMPTY_ON_FAIL(buffer->ReadBits(&frame_cropping_flag, 1)); |
| 189 if (frame_cropping_flag) { | 175 if (frame_cropping_flag) { |
| 190 // frame_crop_{left, right, top, bottom}_offset: ue(v) | 176 // frame_crop_{left, right, top, bottom}_offset: ue(v) |
| 191 RETURN_FALSE_ON_FAIL(parser.ReadExponentialGolomb(&frame_crop_left_offset)); | 177 RETURN_EMPTY_ON_FAIL( |
| 192 RETURN_FALSE_ON_FAIL( | 178 buffer->ReadExponentialGolomb(&frame_crop_left_offset)); |
| 193 parser.ReadExponentialGolomb(&frame_crop_right_offset)); | 179 RETURN_EMPTY_ON_FAIL( |
| 194 RETURN_FALSE_ON_FAIL(parser.ReadExponentialGolomb(&frame_crop_top_offset)); | 180 buffer->ReadExponentialGolomb(&frame_crop_right_offset)); |
| 195 RETURN_FALSE_ON_FAIL( | 181 RETURN_EMPTY_ON_FAIL(buffer->ReadExponentialGolomb(&frame_crop_top_offset)); |
| 196 parser.ReadExponentialGolomb(&frame_crop_bottom_offset)); | 182 RETURN_EMPTY_ON_FAIL( |
| 183 buffer->ReadExponentialGolomb(&frame_crop_bottom_offset)); |
| 197 } | 184 } |
| 185 // vui_parameters_present_flag: u(1) |
| 186 RETURN_EMPTY_ON_FAIL(buffer->ReadBits(&sps.vui_params_present, 1)); |
| 198 | 187 |
| 199 // Far enough! We don't use the rest of the SPS. | 188 // Far enough! We don't use the rest of the SPS. |
| 200 | 189 |
| 201 // Start with the resolution determined by the pic_width/pic_height fields. | 190 // Start with the resolution determined by the pic_width/pic_height fields. |
| 202 int width = 16 * (pic_width_in_mbs_minus1 + 1); | 191 sps.width = 16 * (pic_width_in_mbs_minus1 + 1); |
| 203 int height = | 192 sps.height = |
| 204 16 * (2 - frame_mbs_only_flag) * (pic_height_in_map_units_minus1 + 1); | 193 16 * (2 - sps.frame_mbs_only_flag) * (pic_height_in_map_units_minus1 + 1); |
| 205 | 194 |
| 206 // Figure out the crop units in pixels. That's based on the chroma format's | 195 // Figure out the crop units in pixels. That's based on the chroma format's |
| 207 // sampling, which is indicated by chroma_format_idc. | 196 // sampling, which is indicated by chroma_format_idc. |
| 208 if (separate_colour_plane_flag || chroma_format_idc == 0) { | 197 if (sps.separate_colour_plane_flag || chroma_format_idc == 0) { |
| 209 frame_crop_bottom_offset *= (2 - frame_mbs_only_flag); | 198 frame_crop_bottom_offset *= (2 - sps.frame_mbs_only_flag); |
| 210 frame_crop_top_offset *= (2 - frame_mbs_only_flag); | 199 frame_crop_top_offset *= (2 - sps.frame_mbs_only_flag); |
| 211 } else if (!separate_colour_plane_flag && chroma_format_idc > 0) { | 200 } else if (!sps.separate_colour_plane_flag && chroma_format_idc > 0) { |
| 212 // Width multipliers for formats 1 (4:2:0) and 2 (4:2:2). | 201 // Width multipliers for formats 1 (4:2:0) and 2 (4:2:2). |
| 213 if (chroma_format_idc == 1 || chroma_format_idc == 2) { | 202 if (chroma_format_idc == 1 || chroma_format_idc == 2) { |
| 214 frame_crop_left_offset *= 2; | 203 frame_crop_left_offset *= 2; |
| 215 frame_crop_right_offset *= 2; | 204 frame_crop_right_offset *= 2; |
| 216 } | 205 } |
| 217 // Height multipliers for format 1 (4:2:0). | 206 // Height multipliers for format 1 (4:2:0). |
| 218 if (chroma_format_idc == 1) { | 207 if (chroma_format_idc == 1) { |
| 219 frame_crop_top_offset *= 2; | 208 frame_crop_top_offset *= 2; |
| 220 frame_crop_bottom_offset *= 2; | 209 frame_crop_bottom_offset *= 2; |
| 221 } | 210 } |
| 222 } | 211 } |
| 223 // Subtract the crop for each dimension. | 212 // Subtract the crop for each dimension. |
| 224 width -= (frame_crop_left_offset + frame_crop_right_offset); | 213 sps.width -= (frame_crop_left_offset + frame_crop_right_offset); |
| 225 height -= (frame_crop_top_offset + frame_crop_bottom_offset); | 214 sps.height -= (frame_crop_top_offset + frame_crop_bottom_offset); |
| 226 | 215 |
| 227 width_ = width; | 216 return OptionalSps(sps); |
| 228 height_ = height; | |
| 229 return true; | |
| 230 } | 217 } |
| 231 | 218 |
| 232 } // namespace webrtc | 219 } // namespace webrtc |
| OLD | NEW |