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" |
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 { | |
23 const int kMaxAbsQpDeltaValue = 51; | |
24 } | |
25 | |
22 namespace webrtc { | 26 namespace webrtc { |
23 | 27 |
24 #define RETURN_ON_FAIL(x, res) \ | 28 #define RETURN_ON_FAIL(x, res) \ |
25 if (!(x)) { \ | 29 if (!(x)) { \ |
26 LOG_F(LS_ERROR) << "FAILED: " #x; \ | 30 LOG_F(LS_ERROR) << "FAILED: " #x; \ |
27 return res; \ | 31 return res; \ |
28 } | 32 } |
29 | 33 |
30 #define RETURN_INV_ON_FAIL(x) RETURN_ON_FAIL(x, kInvalidStream) | 34 #define RETURN_INV_ON_FAIL(x) RETURN_ON_FAIL(x, kInvalidStream) |
31 | 35 |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
244 } | 248 } |
245 if (pps_->entropy_coding_mode_flag && | 249 if (pps_->entropy_coding_mode_flag && |
246 slice_type != H264::SliceType::kI && slice_type != H264::SliceType::kSi) { | 250 slice_type != H264::SliceType::kI && slice_type != H264::SliceType::kSi) { |
247 // cabac_init_idc: ue(v) | 251 // cabac_init_idc: ue(v) |
248 RETURN_INV_ON_FAIL(slice_reader.ReadExponentialGolomb(&golomb_tmp)); | 252 RETURN_INV_ON_FAIL(slice_reader.ReadExponentialGolomb(&golomb_tmp)); |
249 } | 253 } |
250 | 254 |
251 int32_t last_slice_qp_delta; | 255 int32_t last_slice_qp_delta; |
252 RETURN_INV_ON_FAIL( | 256 RETURN_INV_ON_FAIL( |
253 slice_reader.ReadSignedExponentialGolomb(&last_slice_qp_delta)); | 257 slice_reader.ReadSignedExponentialGolomb(&last_slice_qp_delta)); |
258 if (abs(last_slice_qp_delta) > kMaxAbsQpDeltaValue) { | |
pbos-webrtc
2016/11/29 15:31:50
"The value of slice_qp_delta shall be limited such
pbos-webrtc
2016/11/29 16:12:42
Sorry, e.g. should this range be depending on pps_
| |
259 // Something has gone wrong, and the parsed value is invalid. | |
260 LOG(LS_WARNING) << "Parsed QP value out of range."; | |
261 return kInvalidStream; | |
262 } | |
263 | |
254 last_slice_qp_delta_ = rtc::Optional<int32_t>(last_slice_qp_delta); | 264 last_slice_qp_delta_ = rtc::Optional<int32_t>(last_slice_qp_delta); |
255 return kOk; | 265 return kOk; |
256 } | 266 } |
257 | 267 |
258 void H264BitstreamParser::ParseSlice(const uint8_t* slice, size_t length) { | 268 void H264BitstreamParser::ParseSlice(const uint8_t* slice, size_t length) { |
259 H264::NaluType nalu_type = H264::ParseNaluType(slice[0]); | 269 H264::NaluType nalu_type = H264::ParseNaluType(slice[0]); |
260 switch (nalu_type) { | 270 switch (nalu_type) { |
261 case H264::NaluType::kSps: { | 271 case H264::NaluType::kSps: { |
262 sps_ = SpsParser::ParseSps(slice + H264::kNaluTypeSize, | 272 sps_ = SpsParser::ParseSps(slice + H264::kNaluTypeSize, |
263 length - H264::kNaluTypeSize); | 273 length - H264::kNaluTypeSize); |
(...skipping 25 matching lines...) Expand all Loading... | |
289 } | 299 } |
290 | 300 |
291 bool H264BitstreamParser::GetLastSliceQp(int* qp) const { | 301 bool H264BitstreamParser::GetLastSliceQp(int* qp) const { |
292 if (!last_slice_qp_delta_ || !pps_) | 302 if (!last_slice_qp_delta_ || !pps_) |
293 return false; | 303 return false; |
294 *qp = 26 + pps_->pic_init_qp_minus26 + *last_slice_qp_delta_; | 304 *qp = 26 + pps_->pic_init_qp_minus26 + *last_slice_qp_delta_; |
295 return true; | 305 return true; |
296 } | 306 } |
297 | 307 |
298 } // namespace webrtc | 308 } // namespace webrtc |
OLD | NEW |