| OLD | NEW |
| 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 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 rtc::Optional<PpsParser::PpsState> PpsParser::ParsePps(const uint8_t* data, | 31 rtc::Optional<PpsParser::PpsState> PpsParser::ParsePps(const uint8_t* data, |
| 32 size_t length) { | 32 size_t length) { |
| 33 // First, parse out rbsp, which is basically the source buffer minus emulation | 33 // First, parse out rbsp, which is basically the source buffer minus emulation |
| 34 // bytes (the last byte of a 0x00 0x00 0x03 sequence). RBSP is defined in | 34 // bytes (the last byte of a 0x00 0x00 0x03 sequence). RBSP is defined in |
| 35 // section 7.3.1 of the H.264 standard. | 35 // section 7.3.1 of the H.264 standard. |
| 36 std::unique_ptr<rtc::Buffer> unpacked_buffer = H264::ParseRbsp(data, length); | 36 std::unique_ptr<rtc::Buffer> unpacked_buffer = H264::ParseRbsp(data, length); |
| 37 rtc::BitBuffer bit_buffer(unpacked_buffer->data(), unpacked_buffer->size()); | 37 rtc::BitBuffer bit_buffer(unpacked_buffer->data(), unpacked_buffer->size()); |
| 38 return ParseInternal(&bit_buffer); | 38 return ParseInternal(&bit_buffer); |
| 39 } | 39 } |
| 40 | 40 |
| 41 bool PpsParser::ParsePpsIds(const uint8_t* data, |
| 42 size_t length, |
| 43 uint32_t* pps_id, |
| 44 uint32_t* sps_id) { |
| 45 RTC_DCHECK(pps_id); |
| 46 RTC_DCHECK(sps_id); |
| 47 // First, parse out rbsp, which is basically the source buffer minus emulation |
| 48 // bytes (the last byte of a 0x00 0x00 0x03 sequence). RBSP is defined in |
| 49 // section 7.3.1 of the H.264 standard. |
| 50 std::unique_ptr<rtc::Buffer> unpacked_buffer = H264::ParseRbsp(data, length); |
| 51 rtc::BitBuffer bit_buffer(unpacked_buffer->data(), unpacked_buffer->size()); |
| 52 return ParsePpsIdsInternal(&bit_buffer, pps_id, sps_id); |
| 53 } |
| 54 |
| 41 rtc::Optional<uint32_t> PpsParser::ParsePpsIdFromSlice(const uint8_t* data, | 55 rtc::Optional<uint32_t> PpsParser::ParsePpsIdFromSlice(const uint8_t* data, |
| 42 size_t length) { | 56 size_t length) { |
| 43 std::unique_ptr<rtc::Buffer> slice_rbsp(H264::ParseRbsp(data, length)); | 57 std::unique_ptr<rtc::Buffer> slice_rbsp(H264::ParseRbsp(data, length)); |
| 44 rtc::BitBuffer slice_reader(slice_rbsp->data(), slice_rbsp->size()); | 58 rtc::BitBuffer slice_reader(slice_rbsp->data(), slice_rbsp->size()); |
| 45 | 59 |
| 46 uint32_t golomb_tmp; | 60 uint32_t golomb_tmp; |
| 47 // first_mb_in_slice: ue(v) | 61 // first_mb_in_slice: ue(v) |
| 48 if (!slice_reader.ReadExponentialGolomb(&golomb_tmp)) | 62 if (!slice_reader.ReadExponentialGolomb(&golomb_tmp)) |
| 49 return rtc::Optional<uint32_t>(); | 63 return rtc::Optional<uint32_t>(); |
| 50 // slice_type: ue(v) | 64 // slice_type: ue(v) |
| 51 if (!slice_reader.ReadExponentialGolomb(&golomb_tmp)) | 65 if (!slice_reader.ReadExponentialGolomb(&golomb_tmp)) |
| 52 return rtc::Optional<uint32_t>(); | 66 return rtc::Optional<uint32_t>(); |
| 53 // pic_parameter_set_id: ue(v) | 67 // pic_parameter_set_id: ue(v) |
| 54 uint32_t slice_pps_id; | 68 uint32_t slice_pps_id; |
| 55 if (!slice_reader.ReadExponentialGolomb(&slice_pps_id)) | 69 if (!slice_reader.ReadExponentialGolomb(&slice_pps_id)) |
| 56 return rtc::Optional<uint32_t>(); | 70 return rtc::Optional<uint32_t>(); |
| 57 return rtc::Optional<uint32_t>(slice_pps_id); | 71 return rtc::Optional<uint32_t>(slice_pps_id); |
| 58 } | 72 } |
| 59 | 73 |
| 60 rtc::Optional<PpsParser::PpsState> PpsParser::ParseInternal( | 74 rtc::Optional<PpsParser::PpsState> PpsParser::ParseInternal( |
| 61 rtc::BitBuffer* bit_buffer) { | 75 rtc::BitBuffer* bit_buffer) { |
| 62 PpsState pps; | 76 PpsState pps; |
| 63 | 77 |
| 78 RETURN_EMPTY_ON_FAIL(ParsePpsIdsInternal(bit_buffer, &pps.id, &pps.sps_id)); |
| 79 |
| 64 uint32_t bits_tmp; | 80 uint32_t bits_tmp; |
| 65 uint32_t golomb_ignored; | 81 uint32_t golomb_ignored; |
| 66 // pic_parameter_set_id: ue(v) | |
| 67 RETURN_EMPTY_ON_FAIL(bit_buffer->ReadExponentialGolomb(&pps.id)); | |
| 68 // seq_parameter_set_id: ue(v) | |
| 69 RETURN_EMPTY_ON_FAIL(bit_buffer->ReadExponentialGolomb(&pps.sps_id)); | |
| 70 // entropy_coding_mode_flag: u(1) | 82 // entropy_coding_mode_flag: u(1) |
| 71 uint32_t entropy_coding_mode_flag; | 83 uint32_t entropy_coding_mode_flag; |
| 72 RETURN_EMPTY_ON_FAIL(bit_buffer->ReadBits(&entropy_coding_mode_flag, 1)); | 84 RETURN_EMPTY_ON_FAIL(bit_buffer->ReadBits(&entropy_coding_mode_flag, 1)); |
| 73 // TODO(pbos): Implement CABAC support if spotted in the wild. | 85 // TODO(pbos): Implement CABAC support if spotted in the wild. |
| 74 RTC_CHECK(entropy_coding_mode_flag == 0) | 86 RTC_CHECK(entropy_coding_mode_flag == 0) |
| 75 << "Don't know how to parse CABAC streams."; | 87 << "Don't know how to parse CABAC streams."; |
| 76 // bottom_field_pic_order_in_frame_present_flag: u(1) | 88 // bottom_field_pic_order_in_frame_present_flag: u(1) |
| 77 uint32_t bottom_field_pic_order_in_frame_present_flag; | 89 uint32_t bottom_field_pic_order_in_frame_present_flag; |
| 78 RETURN_EMPTY_ON_FAIL( | 90 RETURN_EMPTY_ON_FAIL( |
| 79 bit_buffer->ReadBits(&bottom_field_pic_order_in_frame_present_flag, 1)); | 91 bit_buffer->ReadBits(&bottom_field_pic_order_in_frame_present_flag, 1)); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 // deblocking_filter_control_present_flag: u(1) | 171 // deblocking_filter_control_present_flag: u(1) |
| 160 // constrained_intra_pred_flag: u(1) | 172 // constrained_intra_pred_flag: u(1) |
| 161 RETURN_EMPTY_ON_FAIL(bit_buffer->ReadBits(&bits_tmp, 2)); | 173 RETURN_EMPTY_ON_FAIL(bit_buffer->ReadBits(&bits_tmp, 2)); |
| 162 // redundant_pic_cnt_present_flag: u(1) | 174 // redundant_pic_cnt_present_flag: u(1) |
| 163 RETURN_EMPTY_ON_FAIL( | 175 RETURN_EMPTY_ON_FAIL( |
| 164 bit_buffer->ReadBits(&pps.redundant_pic_cnt_present_flag, 1)); | 176 bit_buffer->ReadBits(&pps.redundant_pic_cnt_present_flag, 1)); |
| 165 | 177 |
| 166 return rtc::Optional<PpsParser::PpsState>(pps); | 178 return rtc::Optional<PpsParser::PpsState>(pps); |
| 167 } | 179 } |
| 168 | 180 |
| 181 bool PpsParser::ParsePpsIdsInternal(rtc::BitBuffer* bit_buffer, |
| 182 uint32_t* pps_id, |
| 183 uint32_t* sps_id) { |
| 184 // pic_parameter_set_id: ue(v) |
| 185 if (!bit_buffer->ReadExponentialGolomb(pps_id)) |
| 186 return false; |
| 187 // seq_parameter_set_id: ue(v) |
| 188 if (!bit_buffer->ReadExponentialGolomb(sps_id)) |
| 189 return false; |
| 190 return true; |
| 191 } |
| 192 |
| 169 } // namespace webrtc | 193 } // namespace webrtc |
| OLD | NEW |