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