| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 #include "webrtc/common_video/h264/h264_bitstream_parser.h" | 10 #include "webrtc/common_video/h264/h264_bitstream_parser.h" |
| 11 | 11 |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "webrtc/base/bitbuffer.h" | 15 #include "webrtc/base/bitbuffer.h" |
| 16 #include "webrtc/base/bytebuffer.h" | |
| 17 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
| 18 | 17 |
| 19 #include "webrtc/common_video/h264/h264_common.h" | 18 #include "webrtc/common_video/h264/h264_common.h" |
| 20 #include "webrtc/base/logging.h" | 19 #include "webrtc/base/logging.h" |
| 21 | 20 |
| 22 namespace { | 21 namespace { |
| 23 const int kMaxAbsQpDeltaValue = 51; | 22 const int kMaxAbsQpDeltaValue = 51; |
| 24 const int kMinQpValue = 0; | 23 const int kMinQpValue = 0; |
| 25 const int kMaxQpValue = 51; | 24 const int kMaxQpValue = 51; |
| 26 } | 25 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 39 H264BitstreamParser::~H264BitstreamParser() {} | 38 H264BitstreamParser::~H264BitstreamParser() {} |
| 40 | 39 |
| 41 H264BitstreamParser::Result H264BitstreamParser::ParseNonParameterSetNalu( | 40 H264BitstreamParser::Result H264BitstreamParser::ParseNonParameterSetNalu( |
| 42 const uint8_t* source, | 41 const uint8_t* source, |
| 43 size_t source_length, | 42 size_t source_length, |
| 44 uint8_t nalu_type) { | 43 uint8_t nalu_type) { |
| 45 if (!sps_ || !pps_) | 44 if (!sps_ || !pps_) |
| 46 return kInvalidStream; | 45 return kInvalidStream; |
| 47 | 46 |
| 48 last_slice_qp_delta_ = rtc::Optional<int32_t>(); | 47 last_slice_qp_delta_ = rtc::Optional<int32_t>(); |
| 49 std::unique_ptr<rtc::Buffer> slice_rbsp( | 48 const std::vector<uint8_t> slice_rbsp = |
| 50 H264::ParseRbsp(source, source_length)); | 49 H264::ParseRbsp(source, source_length); |
| 51 if (slice_rbsp->size() < H264::kNaluTypeSize) | 50 if (slice_rbsp.size() < H264::kNaluTypeSize) |
| 52 return kInvalidStream; | 51 return kInvalidStream; |
| 53 | 52 |
| 54 rtc::BitBuffer slice_reader(slice_rbsp->data() + H264::kNaluTypeSize, | 53 rtc::BitBuffer slice_reader(slice_rbsp.data() + H264::kNaluTypeSize, |
| 55 slice_rbsp->size() - H264::kNaluTypeSize); | 54 slice_rbsp.size() - H264::kNaluTypeSize); |
| 56 // Check to see if this is an IDR slice, which has an extra field to parse | 55 // Check to see if this is an IDR slice, which has an extra field to parse |
| 57 // out. | 56 // out. |
| 58 bool is_idr = (source[0] & 0x0F) == H264::NaluType::kIdr; | 57 bool is_idr = (source[0] & 0x0F) == H264::NaluType::kIdr; |
| 59 uint8_t nal_ref_idc = (source[0] & 0x60) >> 5; | 58 uint8_t nal_ref_idc = (source[0] & 0x60) >> 5; |
| 60 uint32_t golomb_tmp; | 59 uint32_t golomb_tmp; |
| 61 uint32_t bits_tmp; | 60 uint32_t bits_tmp; |
| 62 | 61 |
| 63 // first_mb_in_slice: ue(v) | 62 // first_mb_in_slice: ue(v) |
| 64 RETURN_INV_ON_FAIL(slice_reader.ReadExponentialGolomb(&golomb_tmp)); | 63 RETURN_INV_ON_FAIL(slice_reader.ReadExponentialGolomb(&golomb_tmp)); |
| 65 // slice_type: ue(v) | 64 // slice_type: ue(v) |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 const int parsed_qp = 26 + pps_->pic_init_qp_minus26 + *last_slice_qp_delta_; | 305 const int parsed_qp = 26 + pps_->pic_init_qp_minus26 + *last_slice_qp_delta_; |
| 307 if (parsed_qp < kMinQpValue || parsed_qp > kMaxQpValue) { | 306 if (parsed_qp < kMinQpValue || parsed_qp > kMaxQpValue) { |
| 308 LOG(LS_ERROR) << "Parsed invalid QP from bitstream."; | 307 LOG(LS_ERROR) << "Parsed invalid QP from bitstream."; |
| 309 return false; | 308 return false; |
| 310 } | 309 } |
| 311 *qp = parsed_qp; | 310 *qp = parsed_qp; |
| 312 return true; | 311 return true; |
| 313 } | 312 } |
| 314 | 313 |
| 315 } // namespace webrtc | 314 } // namespace webrtc |
| OLD | NEW |