OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 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 <algorithm> | 11 #include <algorithm> |
12 | 12 |
13 #include "webrtc/base/array_view.h" | 13 #include "webrtc/base/array_view.h" |
14 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 14 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
15 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" | 15 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h" |
16 #include "webrtc/voice_engine/transport_feedback_packet_loss_tracker.h" | 16 #include "webrtc/voice_engine/transport_feedback_packet_loss_tracker.h" |
17 | 17 |
18 namespace webrtc { | 18 namespace webrtc { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 template <typename T> | |
23 T FuzzInput(const uint8_t*& data, size_t& size) { | |
minyue-webrtc
2017/01/25 09:38:45
const uint8_t*& -> uint8_t const**
size_t& -> si
elad.alon_webrtc.org
2017/01/25 12:47:54
For the future instances - is the guideline "const
minyue-webrtc
2017/01/25 13:54:56
Rather simple: see https://google.github.io/styleg
| |
24 RTC_CHECK(size >= sizeof(T)); | |
25 T rc = ByteReader<T>::ReadBigEndian(data); | |
26 data += sizeof(T); | |
27 size -= sizeof(T); | |
28 return rc; | |
29 } | |
30 | |
22 class TransportFeedbackGenerator { | 31 class TransportFeedbackGenerator { |
23 public: | 32 public: |
24 explicit TransportFeedbackGenerator(rtc::ArrayView<const uint8_t> data) | 33 explicit TransportFeedbackGenerator(rtc::ArrayView<const uint8_t> data) |
25 : data_(data), ended_(false), data_idx_(0) {} | 34 : data_(data), ended_(false), data_idx_(0) {} |
26 | 35 |
27 void GetNextTransportFeedback(rtcp::TransportFeedback* feedback) { | 36 void GetNextTransportFeedback(rtcp::TransportFeedback* feedback) { |
28 uint16_t base_seq_num = 0; | 37 uint16_t base_seq_num = 0; |
29 if (!ReadData<uint16_t>(&base_seq_num)) { | 38 if (!ReadData<uint16_t>(&base_seq_num)) { |
30 return; | 39 return; |
31 } | 40 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 } | 83 } |
75 | 84 |
76 const rtc::ArrayView<const uint8_t> data_; | 85 const rtc::ArrayView<const uint8_t> data_; |
77 bool ended_; | 86 bool ended_; |
78 size_t data_idx_; | 87 size_t data_idx_; |
79 }; | 88 }; |
80 | 89 |
81 } // namespace | 90 } // namespace |
82 | 91 |
83 void FuzzOneInput(const uint8_t* data, size_t size) { | 92 void FuzzOneInput(const uint8_t* data, size_t size) { |
84 if (size < sizeof(uint32_t)) { | 93 if (size < 3 * sizeof(uint16_t)) { |
85 return; | 94 return; |
86 } | 95 } |
87 constexpr size_t kSeqNumHalf = 0x8000u; | 96 constexpr size_t kSeqNumHalf = 0x8000u; |
88 const size_t window_size_1 = std::min<size_t>( | 97 |
98 // Produce min-window, max-window and min_pairs_num_for_rplr, such that: | |
99 // a. min <= max <= kSeqNumHalf | |
100 // b. 1 <= min_pairs_num_for_rplr <= max - 1 (fencepost) | |
101 // Because of /b/, both min and max can't be below 2. | |
102 | |
103 const size_t window_size_1 = std::min( | |
89 kSeqNumHalf, | 104 kSeqNumHalf, |
90 std::max<uint16_t>(1, ByteReader<uint16_t>::ReadBigEndian(data))); | 105 static_cast<size_t>(std::max(static_cast<uint16_t>(2), |
minyue-webrtc
2017/01/25 09:38:45
use std::min<size_t> and std::max<uint16_t> to avo
elad.alon_webrtc.org
2017/01/25 12:47:54
Done.
| |
91 data += sizeof(uint16_t); | 106 FuzzInput<uint16_t>(data, size)))); |
92 const size_t window_size_2 = std::min<size_t>( | 107 const size_t window_size_2 = std::min( |
93 kSeqNumHalf, | 108 kSeqNumHalf, |
94 std::max<uint16_t>(1, ByteReader<uint16_t>::ReadBigEndian(data))); | 109 static_cast<size_t>(std::max(static_cast<uint16_t>(2), |
95 data += sizeof(uint16_t); | 110 FuzzInput<uint16_t>(data, size)))); |
96 size -= 2 * sizeof(uint16_t); | 111 const size_t min_window_size = std::min(window_size_1, window_size_2); |
112 const size_t max_window_size = std::max(window_size_1, window_size_2); | |
113 const size_t min_pairs_num_for_rplr = std::min( | |
114 max_window_size - 1, | |
115 static_cast<size_t>(std::max(static_cast<uint16_t>(1), | |
minyue-webrtc
2017/01/25 09:38:45
use max<uint16_t> and min<size_t>
elad.alon_webrtc.org
2017/01/25 12:47:54
Done.
| |
116 FuzzInput<uint16_t>(data, size)))); | |
97 | 117 |
98 TransportFeedbackPacketLossTracker tracker( | 118 TransportFeedbackPacketLossTracker tracker( |
99 std::min(window_size_1, window_size_2), | 119 min_window_size, max_window_size, min_pairs_num_for_rplr); |
100 std::max(window_size_1, window_size_2)); | |
101 TransportFeedbackGenerator feedback_generator( | 120 TransportFeedbackGenerator feedback_generator( |
102 rtc::ArrayView<const uint8_t>(data, size)); | 121 rtc::ArrayView<const uint8_t>(data, size)); |
103 while (!feedback_generator.ended()) { | 122 while (!feedback_generator.ended()) { |
104 rtcp::TransportFeedback feedback; | 123 rtcp::TransportFeedback feedback; |
105 feedback_generator.GetNextTransportFeedback(&feedback); | 124 feedback_generator.GetNextTransportFeedback(&feedback); |
106 tracker.OnReceivedTransportFeedback(feedback); | 125 tracker.OnReceivedTransportFeedback(feedback); |
107 tracker.Validate(); | 126 tracker.Validate(); |
108 } | 127 } |
109 } | 128 } |
110 | 129 |
111 } // namespace webrtc | 130 } // namespace webrtc |
OLD | NEW |